thrift 0.9.3.0 → 0.18.1
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.
- checksums.yaml +7 -0
 - data/ext/compact_protocol.c +1 -0
 - data/ext/struct.c +14 -1
 - data/ext/thrift_native.c +17 -0
 - data/lib/thrift/client.rb +10 -2
 - data/lib/thrift/processor.rb +10 -3
 - data/lib/thrift/protocol/base_protocol.rb +11 -3
 - data/lib/thrift/protocol/binary_protocol.rb +8 -1
 - data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
 - data/lib/thrift/protocol/compact_protocol.rb +8 -0
 - data/lib/thrift/protocol/json_protocol.rb +21 -4
 - data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
 - data/lib/thrift/server/base_server.rb +8 -2
 - data/lib/thrift/server/simple_server.rb +5 -1
 - data/lib/thrift/server/thread_pool_server.rb +5 -1
 - data/lib/thrift/server/threaded_server.rb +5 -1
 - data/lib/thrift/transport/base_server_transport.rb +1 -1
 - data/lib/thrift/transport/base_transport.rb +8 -0
 - data/lib/thrift/transport/buffered_transport.rb +9 -1
 - data/lib/thrift/transport/framed_transport.rb +9 -1
 - data/lib/thrift/transport/http_client_transport.rb +7 -0
 - data/lib/thrift/transport/io_stream_transport.rb +4 -1
 - data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
 - data/lib/thrift/transport/server_socket.rb +6 -1
 - data/lib/thrift/transport/socket.rb +21 -17
 - data/lib/thrift/transport/ssl_server_socket.rb +41 -0
 - data/lib/thrift/transport/ssl_socket.rb +51 -0
 - data/lib/thrift/transport/unix_server_socket.rb +5 -1
 - data/lib/thrift/transport/unix_socket.rb +5 -1
 - data/lib/thrift.rb +6 -4
 - data/spec/base_protocol_spec.rb +79 -71
 - data/spec/base_transport_spec.rb +155 -117
 - data/spec/binary_protocol_accelerated_spec.rb +6 -2
 - data/spec/binary_protocol_spec.rb +16 -8
 - data/spec/binary_protocol_spec_shared.rb +75 -72
 - data/spec/bytes_spec.rb +38 -38
 - data/spec/client_spec.rb +43 -42
 - data/spec/compact_protocol_spec.rb +32 -17
 - data/spec/exception_spec.rb +54 -54
 - data/spec/flat_spec.rb +5 -5
 - data/spec/http_client_spec.rb +74 -33
 - data/spec/json_protocol_spec.rb +170 -131
 - data/spec/namespaced_spec.rb +5 -5
 - data/spec/nonblocking_server_spec.rb +16 -16
 - data/spec/processor_spec.rb +26 -26
 - data/spec/serializer_spec.rb +20 -20
 - data/spec/server_socket_spec.rb +27 -22
 - data/spec/server_spec.rb +91 -51
 - data/spec/socket_spec.rb +23 -16
 - data/spec/socket_spec_shared.rb +31 -31
 - data/spec/spec_helper.rb +6 -1
 - data/spec/ssl_server_socket_spec.rb +34 -0
 - data/spec/ssl_socket_spec.rb +78 -0
 - data/spec/struct_nested_containers_spec.rb +24 -24
 - data/spec/struct_spec.rb +120 -120
 - data/spec/thin_http_server_spec.rb +18 -18
 - data/spec/types_spec.rb +56 -53
 - data/spec/union_spec.rb +47 -41
 - data/spec/unix_socket_spec.rb +43 -34
 - metadata +195 -146
 
| 
         @@ -27,34 +27,34 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       27 
27 
     | 
    
         
             
              end
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
              it "should define the proper VERSION_1, VERSION_MASK AND TYPE_MASK" do
         
     | 
| 
       30 
     | 
    
         
            -
                protocol_class.const_get(:VERSION_MASK). 
     | 
| 
       31 
     | 
    
         
            -
                protocol_class.const_get(:VERSION_1). 
     | 
| 
       32 
     | 
    
         
            -
                protocol_class.const_get(:TYPE_MASK). 
     | 
| 
      
 30 
     | 
    
         
            +
                expect(protocol_class.const_get(:VERSION_MASK)).to eq(0xffff0000)
         
     | 
| 
      
 31 
     | 
    
         
            +
                expect(protocol_class.const_get(:VERSION_1)).to eq(0x80010000)
         
     | 
| 
      
 32 
     | 
    
         
            +
                expect(protocol_class.const_get(:TYPE_MASK)).to eq(0x000000ff)
         
     | 
| 
       33 
33 
     | 
    
         
             
              end
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         
             
              it "should make strict_read readable" do
         
     | 
| 
       36 
     | 
    
         
            -
                @prot.strict_read. 
     | 
| 
      
 36 
     | 
    
         
            +
                expect(@prot.strict_read).to eql(true)
         
     | 
| 
       37 
37 
     | 
    
         
             
              end
         
     | 
| 
       38 
38 
     | 
    
         | 
| 
       39 
39 
     | 
    
         
             
              it "should make strict_write readable" do
         
     | 
| 
       40 
     | 
    
         
            -
                @prot.strict_write. 
     | 
| 
      
 40 
     | 
    
         
            +
                expect(@prot.strict_write).to eql(true)
         
     | 
| 
       41 
41 
     | 
    
         
             
              end    
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
43 
     | 
    
         
             
              it "should write the message header" do
         
     | 
| 
       44 
44 
     | 
    
         
             
                @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
         
     | 
| 
       45 
     | 
    
         
            -
                @trans.read(@trans.available). 
     | 
| 
      
 45 
     | 
    
         
            +
                expect(@trans.read(@trans.available)).to eq([protocol_class.const_get(:VERSION_1) | Thrift::MessageTypes::CALL, "testMessage".size, "testMessage", 17].pack("NNa11N"))
         
     | 
| 
       46 
46 
     | 
    
         
             
              end
         
     | 
| 
       47 
47 
     | 
    
         | 
| 
       48 
48 
     | 
    
         
             
              it "should write the message header without version when writes are not strict" do
         
     | 
| 
       49 
49 
     | 
    
         
             
                @prot = protocol_class.new(@trans, true, false) # no strict write
         
     | 
| 
       50 
50 
     | 
    
         
             
                @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
         
     | 
| 
       51 
     | 
    
         
            -
                @trans.read(@trans.available). 
     | 
| 
      
 51 
     | 
    
         
            +
                expect(@trans.read(@trans.available)).to eq("\000\000\000\vtestMessage\001\000\000\000\021")
         
     | 
| 
       52 
52 
     | 
    
         
             
              end
         
     | 
| 
       53 
53 
     | 
    
         | 
| 
       54 
54 
     | 
    
         
             
              it "should write the message header with a version when writes are strict" do
         
     | 
| 
       55 
55 
     | 
    
         
             
                @prot = protocol_class.new(@trans) # strict write
         
     | 
| 
       56 
56 
     | 
    
         
             
                @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
         
     | 
| 
       57 
     | 
    
         
            -
                @trans.read(@trans.available). 
     | 
| 
      
 57 
     | 
    
         
            +
                expect(@trans.read(@trans.available)).to eq("\200\001\000\001\000\000\000\vtestMessage\000\000\000\021")
         
     | 
| 
       58 
58 
     | 
    
         
             
              end
         
     | 
| 
       59 
59 
     | 
    
         | 
| 
       60 
60 
     | 
    
         | 
| 
         @@ -62,64 +62,67 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       62 
62 
     | 
    
         | 
| 
       63 
63 
     | 
    
         
             
              it "should write the field header" do
         
     | 
| 
       64 
64 
     | 
    
         
             
                @prot.write_field_begin('foo', Thrift::Types::DOUBLE, 3)
         
     | 
| 
       65 
     | 
    
         
            -
                @trans.read(@trans.available). 
     | 
| 
      
 65 
     | 
    
         
            +
                expect(@trans.read(@trans.available)).to eq([Thrift::Types::DOUBLE, 3].pack("cn"))
         
     | 
| 
       66 
66 
     | 
    
         
             
              end
         
     | 
| 
       67 
67 
     | 
    
         | 
| 
       68 
68 
     | 
    
         
             
              # field footer is a noop
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
       70 
70 
     | 
    
         
             
              it "should write the STOP field" do
         
     | 
| 
       71 
71 
     | 
    
         
             
                @prot.write_field_stop
         
     | 
| 
       72 
     | 
    
         
            -
                @trans.read(1). 
     | 
| 
      
 72 
     | 
    
         
            +
                expect(@trans.read(1)).to eq("\000")
         
     | 
| 
       73 
73 
     | 
    
         
             
              end
         
     | 
| 
       74 
74 
     | 
    
         | 
| 
       75 
75 
     | 
    
         
             
              it "should write the map header" do
         
     | 
| 
       76 
76 
     | 
    
         
             
                @prot.write_map_begin(Thrift::Types::STRING, Thrift::Types::LIST, 17)
         
     | 
| 
       77 
     | 
    
         
            -
                @trans.read(@trans.available). 
     | 
| 
      
 77 
     | 
    
         
            +
                expect(@trans.read(@trans.available)).to eq([Thrift::Types::STRING, Thrift::Types::LIST, 17].pack("ccN"));
         
     | 
| 
       78 
78 
     | 
    
         
             
              end
         
     | 
| 
       79 
79 
     | 
    
         | 
| 
       80 
80 
     | 
    
         
             
              # map footer is a noop
         
     | 
| 
       81 
81 
     | 
    
         | 
| 
       82 
82 
     | 
    
         
             
              it "should write the list header" do
         
     | 
| 
       83 
83 
     | 
    
         
             
                @prot.write_list_begin(Thrift::Types::I16, 42)
         
     | 
| 
       84 
     | 
    
         
            -
                @trans.read(@trans.available). 
     | 
| 
      
 84 
     | 
    
         
            +
                expect(@trans.read(@trans.available)).to eq([Thrift::Types::I16, 42].pack("cN"))
         
     | 
| 
       85 
85 
     | 
    
         
             
              end
         
     | 
| 
       86 
86 
     | 
    
         | 
| 
       87 
87 
     | 
    
         
             
              # list footer is a noop
         
     | 
| 
       88 
88 
     | 
    
         | 
| 
       89 
89 
     | 
    
         
             
              it "should write the set header" do
         
     | 
| 
       90 
90 
     | 
    
         
             
                @prot.write_set_begin(Thrift::Types::I16, 42)
         
     | 
| 
       91 
     | 
    
         
            -
                @trans.read(@trans.available). 
     | 
| 
      
 91 
     | 
    
         
            +
                expect(@trans.read(@trans.available)).to eq([Thrift::Types::I16, 42].pack("cN"))
         
     | 
| 
       92 
92 
     | 
    
         
             
              end
         
     | 
| 
       93 
93 
     | 
    
         | 
| 
       94 
94 
     | 
    
         
             
              it "should write a bool" do
         
     | 
| 
       95 
95 
     | 
    
         
             
                @prot.write_bool(true)
         
     | 
| 
       96 
96 
     | 
    
         
             
                @prot.write_bool(false)
         
     | 
| 
       97 
     | 
    
         
            -
                @trans.read(@trans.available). 
     | 
| 
      
 97 
     | 
    
         
            +
                expect(@trans.read(@trans.available)).to eq("\001\000")
         
     | 
| 
       98 
98 
     | 
    
         
             
              end
         
     | 
| 
       99 
99 
     | 
    
         | 
| 
       100 
100 
     | 
    
         
             
              it "should treat a nil bool as false" do
         
     | 
| 
       101 
101 
     | 
    
         
             
                @prot.write_bool(nil)
         
     | 
| 
       102 
     | 
    
         
            -
                @trans.read(1). 
     | 
| 
      
 102 
     | 
    
         
            +
                expect(@trans.read(1)).to eq("\000")
         
     | 
| 
       103 
103 
     | 
    
         
             
              end
         
     | 
| 
       104 
104 
     | 
    
         | 
| 
       105 
105 
     | 
    
         
             
              it "should write a byte" do
         
     | 
| 
       106 
106 
     | 
    
         
             
                # byte is small enough, let's check -128..127
         
     | 
| 
       107 
107 
     | 
    
         
             
                (-128..127).each do |i|
         
     | 
| 
       108 
108 
     | 
    
         
             
                  @prot.write_byte(i)
         
     | 
| 
       109 
     | 
    
         
            -
                  @trans.read(1). 
     | 
| 
      
 109 
     | 
    
         
            +
                  expect(@trans.read(1)).to eq([i].pack('c'))
         
     | 
| 
       110 
110 
     | 
    
         
             
                end
         
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
      
 111 
     | 
    
         
            +
              end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
              it "should clip numbers out of signed range" do
         
     | 
| 
       113 
114 
     | 
    
         
             
                (128..255).each do |i|
         
     | 
| 
       114 
115 
     | 
    
         
             
                  @prot.write_byte(i)
         
     | 
| 
       115 
     | 
    
         
            -
                  @trans.read(1). 
     | 
| 
      
 116 
     | 
    
         
            +
                  expect(@trans.read(1)).to eq([i].pack('c'))
         
     | 
| 
       116 
117 
     | 
    
         
             
                end
         
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
      
 118 
     | 
    
         
            +
              end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
              it "errors out with a Bignum" do
         
     | 
| 
      
 121 
     | 
    
         
            +
                expect { @prot.write_byte(2**65) }.to raise_error(RangeError)
         
     | 
| 
       119 
122 
     | 
    
         
             
              end
         
     | 
| 
       120 
123 
     | 
    
         | 
| 
       121 
124 
     | 
    
         
             
              it "should error gracefully when trying to write a nil byte" do
         
     | 
| 
       122 
     | 
    
         
            -
                 
     | 
| 
      
 125 
     | 
    
         
            +
                expect { @prot.write_byte(nil) }.to raise_error
         
     | 
| 
       123 
126 
     | 
    
         
             
              end
         
     | 
| 
       124 
127 
     | 
    
         | 
| 
       125 
128 
     | 
    
         
             
              it "should write an i16" do
         
     | 
| 
         @@ -131,14 +134,14 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       131 
134 
     | 
    
         
             
                # and try something out of signed range, it should clip
         
     | 
| 
       132 
135 
     | 
    
         
             
                @prot.write_i16(2**15 + 5)
         
     | 
| 
       133 
136 
     | 
    
         | 
| 
       134 
     | 
    
         
            -
                @trans.read(@trans.available). 
     | 
| 
      
 137 
     | 
    
         
            +
                expect(@trans.read(@trans.available)).to eq("\200\000\374\000\000\021\000\000\330\360\006\273\177\377\200\005")
         
     | 
| 
       135 
138 
     | 
    
         | 
| 
       136 
139 
     | 
    
         
             
                # a Bignum should error
         
     | 
| 
       137 
140 
     | 
    
         
             
                # lambda { @prot.write_i16(2**65) }.should raise_error(RangeError)
         
     | 
| 
       138 
141 
     | 
    
         
             
              end
         
     | 
| 
       139 
142 
     | 
    
         | 
| 
       140 
143 
     | 
    
         
             
              it "should error gracefully when trying to write a nil i16" do
         
     | 
| 
       141 
     | 
    
         
            -
                 
     | 
| 
      
 144 
     | 
    
         
            +
                expect { @prot.write_i16(nil) }.to raise_error
         
     | 
| 
       142 
145 
     | 
    
         
             
              end
         
     | 
| 
       143 
146 
     | 
    
         | 
| 
       144 
147 
     | 
    
         
             
              it "should write an i32" do
         
     | 
| 
         @@ -148,14 +151,14 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       148 
151 
     | 
    
         
             
                  @prot.write_i32(i)
         
     | 
| 
       149 
152 
     | 
    
         
             
                end
         
     | 
| 
       150 
153 
     | 
    
         
             
                # try something out of signed range, it should clip
         
     | 
| 
       151 
     | 
    
         
            -
                @trans.read(@trans.available). 
     | 
| 
      
 154 
     | 
    
         
            +
                expect(@trans.read(@trans.available)).to eq("\200\000\000\000" + "\377\376\037\r" + "\377\377\366\034" + "\377\377\377\375" + "\000\000\000\000" + "\000#\340\203" + "\000\0000+" + "\177\377\377\377")
         
     | 
| 
       152 
155 
     | 
    
         
             
                [2 ** 31 + 5, 2 ** 65 + 5].each do |i|
         
     | 
| 
       153 
     | 
    
         
            -
                   
     | 
| 
      
 156 
     | 
    
         
            +
                  expect { @prot.write_i32(i) }.to raise_error(RangeError)  
         
     | 
| 
       154 
157 
     | 
    
         
             
                end
         
     | 
| 
       155 
158 
     | 
    
         
             
              end
         
     | 
| 
       156 
159 
     | 
    
         | 
| 
       157 
160 
     | 
    
         
             
              it "should error gracefully when trying to write a nil i32" do
         
     | 
| 
       158 
     | 
    
         
            -
                 
     | 
| 
      
 161 
     | 
    
         
            +
                expect { @prot.write_i32(nil) }.to raise_error
         
     | 
| 
       159 
162 
     | 
    
         
             
              end
         
     | 
| 
       160 
163 
     | 
    
         | 
| 
       161 
164 
     | 
    
         
             
              it "should write an i64" do
         
     | 
| 
         @@ -165,7 +168,7 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       165 
168 
     | 
    
         
             
                  @prot.write_i64(i)
         
     | 
| 
       166 
169 
     | 
    
         
             
                end
         
     | 
| 
       167 
170 
     | 
    
         
             
                # try something out of signed range, it should clip
         
     | 
| 
       168 
     | 
    
         
            -
                @trans.read(@trans.available). 
     | 
| 
      
 171 
     | 
    
         
            +
                expect(@trans.read(@trans.available)).to eq(["\200\000\000\000\000\000\000\000",
         
     | 
| 
       169 
172 
     | 
    
         
             
                  "\377\377\364\303\035\244+]",
         
     | 
| 
       170 
173 
     | 
    
         
             
                  "\377\377\377\377\376\231:\341",
         
     | 
| 
       171 
174 
     | 
    
         
             
                  "\377\377\377\377\377\377\377\026",
         
     | 
| 
         @@ -173,12 +176,12 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       173 
176 
     | 
    
         
             
                  "\000\000\000\000\000\000\004\317",
         
     | 
| 
       174 
177 
     | 
    
         
             
                  "\000\000\000\000\000#\340\204",
         
     | 
| 
       175 
178 
     | 
    
         
             
                  "\000\000\000\002\340\311~\365",
         
     | 
| 
       176 
     | 
    
         
            -
                  "\177\377\377\377\377\377\377\377"].join("")
         
     | 
| 
       177 
     | 
    
         
            -
                 
     | 
| 
      
 179 
     | 
    
         
            +
                  "\177\377\377\377\377\377\377\377"].join(""))
         
     | 
| 
      
 180 
     | 
    
         
            +
                expect { @prot.write_i64(2 ** 65 + 5) }.to raise_error(RangeError)
         
     | 
| 
       178 
181 
     | 
    
         
             
              end
         
     | 
| 
       179 
182 
     | 
    
         | 
| 
       180 
183 
     | 
    
         
             
              it "should error gracefully when trying to write a nil i64" do
         
     | 
| 
       181 
     | 
    
         
            -
                 
     | 
| 
      
 184 
     | 
    
         
            +
                expect { @prot.write_i64(nil) }.to raise_error
         
     | 
| 
       182 
185 
     | 
    
         
             
              end
         
     | 
| 
       183 
186 
     | 
    
         | 
| 
       184 
187 
     | 
    
         
             
              it "should write a double" do
         
     | 
| 
         @@ -186,12 +189,12 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       186 
189 
     | 
    
         
             
                values = [Float::MIN,-1231.15325, -123123.23, -23.23515123, 0, 12351.1325, 523.23, Float::MAX]
         
     | 
| 
       187 
190 
     | 
    
         
             
                values.each do |f|
         
     | 
| 
       188 
191 
     | 
    
         
             
                  @prot.write_double(f)
         
     | 
| 
       189 
     | 
    
         
            -
                  @trans.read(@trans.available). 
     | 
| 
      
 192 
     | 
    
         
            +
                  expect(@trans.read(@trans.available)).to eq([f].pack("G"))
         
     | 
| 
       190 
193 
     | 
    
         
             
                end
         
     | 
| 
       191 
194 
     | 
    
         
             
              end
         
     | 
| 
       192 
195 
     | 
    
         | 
| 
       193 
196 
     | 
    
         
             
              it "should error gracefully when trying to write a nil double" do
         
     | 
| 
       194 
     | 
    
         
            -
                 
     | 
| 
      
 197 
     | 
    
         
            +
                expect { @prot.write_double(nil) }.to raise_error
         
     | 
| 
       195 
198 
     | 
    
         
             
              end
         
     | 
| 
       196 
199 
     | 
    
         | 
| 
       197 
200 
     | 
    
         
             
              if RUBY_VERSION >= '1.9'
         
     | 
| 
         @@ -199,111 +202,111 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       199 
202 
     | 
    
         
             
                  str = 'abc'
         
     | 
| 
       200 
203 
     | 
    
         
             
                  @prot.write_string(str)
         
     | 
| 
       201 
204 
     | 
    
         
             
                  a = @trans.read(@trans.available)
         
     | 
| 
       202 
     | 
    
         
            -
                  a.encoding. 
     | 
| 
       203 
     | 
    
         
            -
                  a.unpack('C*'). 
     | 
| 
      
 205 
     | 
    
         
            +
                  expect(a.encoding).to eq(Encoding::BINARY)
         
     | 
| 
      
 206 
     | 
    
         
            +
                  expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63])
         
     | 
| 
       204 
207 
     | 
    
         
             
                end
         
     | 
| 
       205 
208 
     | 
    
         | 
| 
       206 
209 
     | 
    
         
             
                it 'should write a string with unicode characters' do
         
     | 
| 
       207 
210 
     | 
    
         
             
                  str = "abc \u20AC \u20AD".encode('UTF-8')
         
     | 
| 
       208 
211 
     | 
    
         
             
                  @prot.write_string(str)
         
     | 
| 
       209 
212 
     | 
    
         
             
                  a = @trans.read(@trans.available)
         
     | 
| 
       210 
     | 
    
         
            -
                  a.encoding. 
     | 
| 
       211 
     | 
    
         
            -
                  a.unpack('C*'). 
     | 
| 
       212 
     | 
    
         
            -
                                            0xE2, 0x82, 0xAC, 0x20, 0xE2, 0x82, 0xAD]
         
     | 
| 
      
 213 
     | 
    
         
            +
                  expect(a.encoding).to eq(Encoding::BINARY)
         
     | 
| 
      
 214 
     | 
    
         
            +
                  expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x0B, 0x61, 0x62, 0x63, 0x20,
         
     | 
| 
      
 215 
     | 
    
         
            +
                                            0xE2, 0x82, 0xAC, 0x20, 0xE2, 0x82, 0xAD])
         
     | 
| 
       213 
216 
     | 
    
         
             
                end
         
     | 
| 
       214 
217 
     | 
    
         | 
| 
       215 
218 
     | 
    
         
             
                it 'should write should write a string with unicode characters and transcoding' do
         
     | 
| 
       216 
219 
     | 
    
         
             
                  str = "abc \u20AC".encode('ISO-8859-15')
         
     | 
| 
       217 
220 
     | 
    
         
             
                  @prot.write_string(str)
         
     | 
| 
       218 
221 
     | 
    
         
             
                  a = @trans.read(@trans.available)
         
     | 
| 
       219 
     | 
    
         
            -
                  a.encoding. 
     | 
| 
       220 
     | 
    
         
            -
                  a.unpack('C*'). 
     | 
| 
      
 222 
     | 
    
         
            +
                  expect(a.encoding).to eq(Encoding::BINARY)
         
     | 
| 
      
 223 
     | 
    
         
            +
                  expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x07, 0x61, 0x62, 0x63, 0x20, 0xE2, 0x82, 0xAC])
         
     | 
| 
       221 
224 
     | 
    
         
             
                end
         
     | 
| 
       222 
225 
     | 
    
         | 
| 
       223 
226 
     | 
    
         
             
                it 'should write a binary string' do
         
     | 
| 
       224 
227 
     | 
    
         
             
                  buffer = [0, 1, 2, 3].pack('C*')
         
     | 
| 
       225 
228 
     | 
    
         
             
                  @prot.write_binary(buffer)
         
     | 
| 
       226 
229 
     | 
    
         
             
                  a = @trans.read(@trans.available)
         
     | 
| 
       227 
     | 
    
         
            -
                  a.encoding. 
     | 
| 
       228 
     | 
    
         
            -
                  a.unpack('C*'). 
     | 
| 
      
 230 
     | 
    
         
            +
                  expect(a.encoding).to eq(Encoding::BINARY)
         
     | 
| 
      
 231 
     | 
    
         
            +
                  expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03])
         
     | 
| 
       229 
232 
     | 
    
         
             
                end
         
     | 
| 
       230 
233 
     | 
    
         
             
              else
         
     | 
| 
       231 
234 
     | 
    
         
             
                it 'should write a string' do
         
     | 
| 
       232 
235 
     | 
    
         
             
                  str = 'abc'
         
     | 
| 
       233 
236 
     | 
    
         
             
                  @prot.write_string(str)
         
     | 
| 
       234 
237 
     | 
    
         
             
                  a = @trans.read(@trans.available)
         
     | 
| 
       235 
     | 
    
         
            -
                  a.unpack('C*'). 
     | 
| 
      
 238 
     | 
    
         
            +
                  expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63])
         
     | 
| 
       236 
239 
     | 
    
         
             
                end
         
     | 
| 
       237 
240 
     | 
    
         | 
| 
       238 
241 
     | 
    
         
             
                it 'should write a binary string' do
         
     | 
| 
       239 
242 
     | 
    
         
             
                  buffer = [0, 1, 2, 3].pack('C*')
         
     | 
| 
       240 
243 
     | 
    
         
             
                  @prot.write_binary(buffer)
         
     | 
| 
       241 
244 
     | 
    
         
             
                  a = @trans.read(@trans.available)
         
     | 
| 
       242 
     | 
    
         
            -
                  a.unpack('C*'). 
     | 
| 
      
 245 
     | 
    
         
            +
                  expect(a.unpack('C*')).to eq([0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03])
         
     | 
| 
       243 
246 
     | 
    
         
             
                end
         
     | 
| 
       244 
247 
     | 
    
         
             
              end
         
     | 
| 
       245 
248 
     | 
    
         | 
| 
       246 
249 
     | 
    
         
             
              it "should error gracefully when trying to write a nil string" do
         
     | 
| 
       247 
     | 
    
         
            -
                 
     | 
| 
      
 250 
     | 
    
         
            +
                expect { @prot.write_string(nil) }.to raise_error
         
     | 
| 
       248 
251 
     | 
    
         
             
              end
         
     | 
| 
       249 
252 
     | 
    
         | 
| 
       250 
253 
     | 
    
         
             
              it "should write the message header without version when writes are not strict" do
         
     | 
| 
       251 
254 
     | 
    
         
             
                @prot = protocol_class.new(@trans, true, false) # no strict write
         
     | 
| 
       252 
255 
     | 
    
         
             
                @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
         
     | 
| 
       253 
     | 
    
         
            -
                @trans.read(@trans.available). 
     | 
| 
      
 256 
     | 
    
         
            +
                expect(@trans.read(@trans.available)).to eq("\000\000\000\vtestMessage\001\000\000\000\021")
         
     | 
| 
       254 
257 
     | 
    
         
             
              end
         
     | 
| 
       255 
258 
     | 
    
         | 
| 
       256 
259 
     | 
    
         
             
              it "should write the message header with a version when writes are strict" do
         
     | 
| 
       257 
260 
     | 
    
         
             
                @prot = protocol_class.new(@trans) # strict write
         
     | 
| 
       258 
261 
     | 
    
         
             
                @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 17)
         
     | 
| 
       259 
     | 
    
         
            -
                @trans.read(@trans.available). 
     | 
| 
      
 262 
     | 
    
         
            +
                expect(@trans.read(@trans.available)).to eq("\200\001\000\001\000\000\000\vtestMessage\000\000\000\021")
         
     | 
| 
       260 
263 
     | 
    
         
             
              end
         
     | 
| 
       261 
264 
     | 
    
         | 
| 
       262 
265 
     | 
    
         
             
              # message footer is a noop
         
     | 
| 
       263 
266 
     | 
    
         | 
| 
       264 
267 
     | 
    
         
             
              it "should read a field header" do
         
     | 
| 
       265 
268 
     | 
    
         
             
                @trans.write([Thrift::Types::STRING, 3].pack("cn"))
         
     | 
| 
       266 
     | 
    
         
            -
                @prot.read_field_begin. 
     | 
| 
      
 269 
     | 
    
         
            +
                expect(@prot.read_field_begin).to eq([nil, Thrift::Types::STRING, 3])
         
     | 
| 
       267 
270 
     | 
    
         
             
              end
         
     | 
| 
       268 
271 
     | 
    
         | 
| 
       269 
272 
     | 
    
         
             
              # field footer is a noop
         
     | 
| 
       270 
273 
     | 
    
         | 
| 
       271 
274 
     | 
    
         
             
              it "should read a stop field" do
         
     | 
| 
       272 
275 
     | 
    
         
             
                @trans.write([Thrift::Types::STOP].pack("c"));
         
     | 
| 
       273 
     | 
    
         
            -
                @prot.read_field_begin. 
     | 
| 
      
 276 
     | 
    
         
            +
                expect(@prot.read_field_begin).to eq([nil, Thrift::Types::STOP, 0])
         
     | 
| 
       274 
277 
     | 
    
         
             
              end
         
     | 
| 
       275 
278 
     | 
    
         | 
| 
       276 
279 
     | 
    
         
             
              it "should read a map header" do
         
     | 
| 
       277 
280 
     | 
    
         
             
                @trans.write([Thrift::Types::DOUBLE, Thrift::Types::I64, 42].pack("ccN"))
         
     | 
| 
       278 
     | 
    
         
            -
                @prot.read_map_begin. 
     | 
| 
      
 281 
     | 
    
         
            +
                expect(@prot.read_map_begin).to eq([Thrift::Types::DOUBLE, Thrift::Types::I64, 42])
         
     | 
| 
       279 
282 
     | 
    
         
             
              end
         
     | 
| 
       280 
283 
     | 
    
         | 
| 
       281 
284 
     | 
    
         
             
              # map footer is a noop
         
     | 
| 
       282 
285 
     | 
    
         | 
| 
       283 
286 
     | 
    
         
             
              it "should read a list header" do
         
     | 
| 
       284 
287 
     | 
    
         
             
                @trans.write([Thrift::Types::STRING, 17].pack("cN"))
         
     | 
| 
       285 
     | 
    
         
            -
                @prot.read_list_begin. 
     | 
| 
      
 288 
     | 
    
         
            +
                expect(@prot.read_list_begin).to eq([Thrift::Types::STRING, 17])
         
     | 
| 
       286 
289 
     | 
    
         
             
              end
         
     | 
| 
       287 
290 
     | 
    
         | 
| 
       288 
291 
     | 
    
         
             
              # list footer is a noop
         
     | 
| 
       289 
292 
     | 
    
         | 
| 
       290 
293 
     | 
    
         
             
              it "should read a set header" do
         
     | 
| 
       291 
294 
     | 
    
         
             
                @trans.write([Thrift::Types::STRING, 17].pack("cN"))
         
     | 
| 
       292 
     | 
    
         
            -
                @prot.read_set_begin. 
     | 
| 
      
 295 
     | 
    
         
            +
                expect(@prot.read_set_begin).to eq([Thrift::Types::STRING, 17])
         
     | 
| 
       293 
296 
     | 
    
         
             
              end
         
     | 
| 
       294 
297 
     | 
    
         | 
| 
       295 
298 
     | 
    
         
             
              # set footer is a noop
         
     | 
| 
       296 
299 
     | 
    
         | 
| 
       297 
300 
     | 
    
         
             
              it "should read a bool" do
         
     | 
| 
       298 
301 
     | 
    
         
             
                @trans.write("\001\000");
         
     | 
| 
       299 
     | 
    
         
            -
                @prot.read_bool. 
     | 
| 
       300 
     | 
    
         
            -
                @prot.read_bool. 
     | 
| 
      
 302 
     | 
    
         
            +
                expect(@prot.read_bool).to eq(true)
         
     | 
| 
      
 303 
     | 
    
         
            +
                expect(@prot.read_bool).to eq(false)
         
     | 
| 
       301 
304 
     | 
    
         
             
              end
         
     | 
| 
       302 
305 
     | 
    
         | 
| 
       303 
306 
     | 
    
         
             
              it "should read a byte" do
         
     | 
| 
       304 
307 
     | 
    
         
             
                [-128, -57, -3, 0, 17, 24, 127].each do |i|
         
     | 
| 
       305 
308 
     | 
    
         
             
                  @trans.write([i].pack("c"))
         
     | 
| 
       306 
     | 
    
         
            -
                  @prot.read_byte. 
     | 
| 
      
 309 
     | 
    
         
            +
                  expect(@prot.read_byte).to eq(i)
         
     | 
| 
       307 
310 
     | 
    
         
             
                end
         
     | 
| 
       308 
311 
     | 
    
         
             
              end
         
     | 
| 
       309 
312 
     | 
    
         | 
| 
         @@ -311,7 +314,7 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       311 
314 
     | 
    
         
             
                # try a scattering of values, including min/max
         
     | 
| 
       312 
315 
     | 
    
         
             
                [-2**15, -5237, -353, 0, 1527, 2234, 2**15-1].each do |i|
         
     | 
| 
       313 
316 
     | 
    
         
             
                  @trans.write([i].pack("n"));
         
     | 
| 
       314 
     | 
    
         
            -
                  @prot.read_i16. 
     | 
| 
      
 317 
     | 
    
         
            +
                  expect(@prot.read_i16).to eq(i)
         
     | 
| 
       315 
318 
     | 
    
         
             
                end
         
     | 
| 
       316 
319 
     | 
    
         
             
              end
         
     | 
| 
       317 
320 
     | 
    
         | 
| 
         @@ -319,7 +322,7 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       319 
322 
     | 
    
         
             
                # try a scattering of values, including min/max
         
     | 
| 
       320 
323 
     | 
    
         
             
                [-2**31, -235125, -6236, 0, 2351, 123123, 2**31-1].each do |i|
         
     | 
| 
       321 
324 
     | 
    
         
             
                  @trans.write([i].pack("N"))
         
     | 
| 
       322 
     | 
    
         
            -
                  @prot.read_i32. 
     | 
| 
      
 325 
     | 
    
         
            +
                  expect(@prot.read_i32).to eq(i)
         
     | 
| 
       323 
326 
     | 
    
         
             
                end
         
     | 
| 
       324 
327 
     | 
    
         
             
              end
         
     | 
| 
       325 
328 
     | 
    
         | 
| 
         @@ -327,7 +330,7 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       327 
330 
     | 
    
         
             
                # try a scattering of values, including min/max
         
     | 
| 
       328 
331 
     | 
    
         
             
                [-2**63, -123512312, -6346, 0, 32, 2346322323, 2**63-1].each do |i|
         
     | 
| 
       329 
332 
     | 
    
         
             
                  @trans.write([i >> 32, i & 0xFFFFFFFF].pack("NN"))
         
     | 
| 
       330 
     | 
    
         
            -
                  @prot.read_i64. 
     | 
| 
      
 333 
     | 
    
         
            +
                  expect(@prot.read_i64).to eq(i)
         
     | 
| 
       331 
334 
     | 
    
         
             
                end
         
     | 
| 
       332 
335 
     | 
    
         
             
              end
         
     | 
| 
       333 
336 
     | 
    
         | 
| 
         @@ -335,7 +338,7 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       335 
338 
     | 
    
         
             
                # try a random scattering of values, including min/max
         
     | 
| 
       336 
339 
     | 
    
         
             
                [Float::MIN, -231231.12351, -323.233513, 0, 123.2351235, 2351235.12351235, Float::MAX].each do |f|
         
     | 
| 
       337 
340 
     | 
    
         
             
                  @trans.write([f].pack("G"));
         
     | 
| 
       338 
     | 
    
         
            -
                  @prot.read_double. 
     | 
| 
      
 341 
     | 
    
         
            +
                  expect(@prot.read_double).to eq(f)
         
     | 
| 
       339 
342 
     | 
    
         
             
                end
         
     | 
| 
       340 
343 
     | 
    
         
             
              end
         
     | 
| 
       341 
344 
     | 
    
         | 
| 
         @@ -345,8 +348,8 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       345 
348 
     | 
    
         
             
                  buffer = [0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63].pack('C*')
         
     | 
| 
       346 
349 
     | 
    
         
             
                  @trans.write(buffer)
         
     | 
| 
       347 
350 
     | 
    
         
             
                  a = @prot.read_string
         
     | 
| 
       348 
     | 
    
         
            -
                  a. 
     | 
| 
       349 
     | 
    
         
            -
                  a.encoding. 
     | 
| 
      
 351 
     | 
    
         
            +
                  expect(a).to eq('abc'.encode('UTF-8'))
         
     | 
| 
      
 352 
     | 
    
         
            +
                  expect(a.encoding).to eq(Encoding::UTF_8)
         
     | 
| 
       350 
353 
     | 
    
         
             
                end
         
     | 
| 
       351 
354 
     | 
    
         | 
| 
       352 
355 
     | 
    
         
             
                it 'should read a string containing unicode characters from UTF-8 encoded buffer' do
         
     | 
| 
         @@ -354,44 +357,44 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       354 
357 
     | 
    
         
             
                  buffer = [0x00, 0x00, 0x00, 0x03, 0xE2, 0x82, 0xAC].pack('C*')
         
     | 
| 
       355 
358 
     | 
    
         
             
                  @trans.write(buffer)
         
     | 
| 
       356 
359 
     | 
    
         
             
                  a = @prot.read_string
         
     | 
| 
       357 
     | 
    
         
            -
                  a. 
     | 
| 
       358 
     | 
    
         
            -
                  a.encoding. 
     | 
| 
      
 360 
     | 
    
         
            +
                  expect(a).to eq("\u20AC".encode('UTF-8'))
         
     | 
| 
      
 361 
     | 
    
         
            +
                  expect(a.encoding).to eq(Encoding::UTF_8)
         
     | 
| 
       359 
362 
     | 
    
         
             
                end
         
     | 
| 
       360 
363 
     | 
    
         | 
| 
       361 
364 
     | 
    
         
             
                it 'should read a binary string' do
         
     | 
| 
       362 
365 
     | 
    
         
             
                  buffer = [0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03].pack('C*')
         
     | 
| 
       363 
366 
     | 
    
         
             
                  @trans.write(buffer)
         
     | 
| 
       364 
367 
     | 
    
         
             
                  a = @prot.read_binary
         
     | 
| 
       365 
     | 
    
         
            -
                  a. 
     | 
| 
       366 
     | 
    
         
            -
                  a.encoding. 
     | 
| 
      
 368 
     | 
    
         
            +
                  expect(a).to eq([0x00, 0x01, 0x02, 0x03].pack('C*'))
         
     | 
| 
      
 369 
     | 
    
         
            +
                  expect(a.encoding).to eq(Encoding::BINARY)
         
     | 
| 
       367 
370 
     | 
    
         
             
                end
         
     | 
| 
       368 
371 
     | 
    
         
             
              else
         
     | 
| 
       369 
372 
     | 
    
         
             
                it 'should read a string' do
         
     | 
| 
       370 
373 
     | 
    
         
             
                  # i32 of value 3, followed by three characters/UTF-8 bytes 'a', 'b', 'c'
         
     | 
| 
       371 
374 
     | 
    
         
             
                  buffer = [0x00, 0x00, 0x00, 0x03, 0x61, 0x62, 0x63].pack('C*')
         
     | 
| 
       372 
375 
     | 
    
         
             
                  @trans.write(buffer)
         
     | 
| 
       373 
     | 
    
         
            -
                  @prot.read_string. 
     | 
| 
      
 376 
     | 
    
         
            +
                  expect(@prot.read_string).to eq('abc')
         
     | 
| 
       374 
377 
     | 
    
         
             
                end
         
     | 
| 
       375 
378 
     | 
    
         | 
| 
       376 
379 
     | 
    
         
             
                it 'should read a binary string' do
         
     | 
| 
       377 
380 
     | 
    
         
             
                  buffer = [0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03].pack('C*')
         
     | 
| 
       378 
381 
     | 
    
         
             
                  @trans.write(buffer)
         
     | 
| 
       379 
382 
     | 
    
         
             
                  a = @prot.read_binary
         
     | 
| 
       380 
     | 
    
         
            -
                  a. 
     | 
| 
      
 383 
     | 
    
         
            +
                  expect(a).to eq([0x00, 0x01, 0x02, 0x03].pack('C*'))
         
     | 
| 
       381 
384 
     | 
    
         
             
                end
         
     | 
| 
       382 
385 
     | 
    
         
             
              end
         
     | 
| 
       383 
386 
     | 
    
         | 
| 
       384 
387 
     | 
    
         
             
              it "should perform a complete rpc with no args or return" do
         
     | 
| 
       385 
388 
     | 
    
         
             
                srv_test(
         
     | 
| 
       386 
389 
     | 
    
         
             
                  proc {|client| client.send_voidMethod()},
         
     | 
| 
       387 
     | 
    
         
            -
                  proc {|client| client.recv_voidMethod. 
     | 
| 
      
 390 
     | 
    
         
            +
                  proc {|client| expect(client.recv_voidMethod).to eq(nil)}
         
     | 
| 
       388 
391 
     | 
    
         
             
                )
         
     | 
| 
       389 
392 
     | 
    
         
             
              end
         
     | 
| 
       390 
393 
     | 
    
         | 
| 
       391 
394 
     | 
    
         
             
              it "should perform a complete rpc with a primitive return type" do
         
     | 
| 
       392 
395 
     | 
    
         
             
                srv_test(
         
     | 
| 
       393 
396 
     | 
    
         
             
                  proc {|client| client.send_primitiveMethod()},
         
     | 
| 
       394 
     | 
    
         
            -
                  proc {|client| client.recv_primitiveMethod. 
     | 
| 
      
 397 
     | 
    
         
            +
                  proc {|client| expect(client.recv_primitiveMethod).to eq(1)}
         
     | 
| 
       395 
398 
     | 
    
         
             
                )
         
     | 
| 
       396 
399 
     | 
    
         
             
              end
         
     | 
| 
       397 
400 
     | 
    
         | 
| 
         @@ -402,7 +405,7 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       402 
405 
     | 
    
         
             
                    result = client.recv_structMethod
         
     | 
| 
       403 
406 
     | 
    
         
             
                    result.set_byte_map = nil
         
     | 
| 
       404 
407 
     | 
    
         
             
                    result.map_byte_map = nil
         
     | 
| 
       405 
     | 
    
         
            -
                    result. 
     | 
| 
      
 408 
     | 
    
         
            +
                    expect(result).to eq(Fixtures::COMPACT_PROTOCOL_TEST_STRUCT)
         
     | 
| 
       406 
409 
     | 
    
         
             
                  }
         
     | 
| 
       407 
410 
     | 
    
         
             
                )
         
     | 
| 
       408 
411 
     | 
    
         
             
              end
         
     | 
| 
         @@ -423,9 +426,9 @@ shared_examples_for 'a binary protocol' do 
     | 
|
| 
       423 
426 
     | 
    
         
             
                clientproto = protocol_class.new(clientside)
         
     | 
| 
       424 
427 
     | 
    
         
             
                serverproto = protocol_class.new(serverside)
         
     | 
| 
       425 
428 
     | 
    
         | 
| 
       426 
     | 
    
         
            -
                processor = Srv::Processor.new(SrvHandler.new)
         
     | 
| 
      
 429 
     | 
    
         
            +
                processor = Thrift::Test::Srv::Processor.new(SrvHandler.new)
         
     | 
| 
       427 
430 
     | 
    
         | 
| 
       428 
     | 
    
         
            -
                client = Srv::Client.new(clientproto, clientproto)
         
     | 
| 
      
 431 
     | 
    
         
            +
                client = Thrift::Test::Srv::Client.new(clientproto, clientproto)
         
     | 
| 
       429 
432 
     | 
    
         | 
| 
       430 
433 
     | 
    
         
             
                # first block
         
     | 
| 
       431 
434 
     | 
    
         
             
                firstblock.call(client)
         
     | 
    
        data/spec/bytes_spec.rb
    CHANGED
    
    | 
         @@ -25,33 +25,33 @@ describe Thrift::Bytes do 
     | 
|
| 
       25 
25 
     | 
    
         
             
                describe '.empty_byte_buffer' do
         
     | 
| 
       26 
26 
     | 
    
         
             
                  it 'should create an empty buffer' do
         
     | 
| 
       27 
27 
     | 
    
         
             
                    b = Thrift::Bytes.empty_byte_buffer
         
     | 
| 
       28 
     | 
    
         
            -
                    b.length. 
     | 
| 
       29 
     | 
    
         
            -
                    b.encoding. 
     | 
| 
      
 28 
     | 
    
         
            +
                    expect(b.length).to eq(0)
         
     | 
| 
      
 29 
     | 
    
         
            +
                    expect(b.encoding).to eq(Encoding::BINARY)
         
     | 
| 
       30 
30 
     | 
    
         
             
                  end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
                  it 'should create an empty buffer of given size' do
         
     | 
| 
       33 
33 
     | 
    
         
             
                    b = Thrift::Bytes.empty_byte_buffer 2
         
     | 
| 
       34 
     | 
    
         
            -
                    b.length. 
     | 
| 
       35 
     | 
    
         
            -
                    b.getbyte(0). 
     | 
| 
       36 
     | 
    
         
            -
                    b.getbyte(1). 
     | 
| 
       37 
     | 
    
         
            -
                    b.encoding. 
     | 
| 
      
 34 
     | 
    
         
            +
                    expect(b.length).to eq(2)
         
     | 
| 
      
 35 
     | 
    
         
            +
                    expect(b.getbyte(0)).to eq(0)
         
     | 
| 
      
 36 
     | 
    
         
            +
                    expect(b.getbyte(1)).to eq(0)
         
     | 
| 
      
 37 
     | 
    
         
            +
                    expect(b.encoding).to eq(Encoding::BINARY)
         
     | 
| 
       38 
38 
     | 
    
         
             
                  end
         
     | 
| 
       39 
39 
     | 
    
         
             
                end
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
                describe '.force_binary_encoding' do
         
     | 
| 
       42 
42 
     | 
    
         
             
                  it 'should change encoding' do
         
     | 
| 
       43 
43 
     | 
    
         
             
                    e = 'STRING'.encode('UTF-8')
         
     | 
| 
       44 
     | 
    
         
            -
                    e.encoding. 
     | 
| 
      
 44 
     | 
    
         
            +
                    expect(e.encoding).not_to eq(Encoding::BINARY)
         
     | 
| 
       45 
45 
     | 
    
         
             
                    a = Thrift::Bytes.force_binary_encoding e
         
     | 
| 
       46 
     | 
    
         
            -
                    a.encoding. 
     | 
| 
      
 46 
     | 
    
         
            +
                    expect(a.encoding).to eq(Encoding::BINARY)
         
     | 
| 
       47 
47 
     | 
    
         
             
                  end
         
     | 
| 
       48 
48 
     | 
    
         
             
                end
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
                describe '.get_string_byte' do
         
     | 
| 
       51 
51 
     | 
    
         
             
                  it 'should get the byte at index' do
         
     | 
| 
       52 
52 
     | 
    
         
             
                    s = "\x41\x42"
         
     | 
| 
       53 
     | 
    
         
            -
                    Thrift::Bytes.get_string_byte(s, 0). 
     | 
| 
       54 
     | 
    
         
            -
                    Thrift::Bytes.get_string_byte(s, 1). 
     | 
| 
      
 53 
     | 
    
         
            +
                    expect(Thrift::Bytes.get_string_byte(s, 0)).to eq(0x41)
         
     | 
| 
      
 54 
     | 
    
         
            +
                    expect(Thrift::Bytes.get_string_byte(s, 1)).to eq(0x42)
         
     | 
| 
       55 
55 
     | 
    
         
             
                  end
         
     | 
| 
       56 
56 
     | 
    
         
             
                end
         
     | 
| 
       57 
57 
     | 
    
         | 
| 
         @@ -59,42 +59,42 @@ describe Thrift::Bytes do 
     | 
|
| 
       59 
59 
     | 
    
         
             
                  it 'should set byte value at index' do
         
     | 
| 
       60 
60 
     | 
    
         
             
                    s = "\x41\x42"
         
     | 
| 
       61 
61 
     | 
    
         
             
                    Thrift::Bytes.set_string_byte(s, 0, 0x43)
         
     | 
| 
       62 
     | 
    
         
            -
                    s.getbyte(0). 
     | 
| 
       63 
     | 
    
         
            -
                    s. 
     | 
| 
      
 62 
     | 
    
         
            +
                    expect(s.getbyte(0)).to eq(0x43)
         
     | 
| 
      
 63 
     | 
    
         
            +
                    expect(s).to eq('CB')
         
     | 
| 
       64 
64 
     | 
    
         
             
                  end
         
     | 
| 
       65 
65 
     | 
    
         
             
                end
         
     | 
| 
       66 
66 
     | 
    
         | 
| 
       67 
67 
     | 
    
         
             
                describe '.convert_to_utf8_byte_buffer' do
         
     | 
| 
       68 
68 
     | 
    
         
             
                  it 'should convert UTF-8 String to byte buffer' do
         
     | 
| 
       69 
69 
     | 
    
         
             
                    e = "\u20AC".encode('UTF-8') # a string with euro sign character U+20AC
         
     | 
| 
       70 
     | 
    
         
            -
                    e.length. 
     | 
| 
      
 70 
     | 
    
         
            +
                    expect(e.length).to eq(1)
         
     | 
| 
       71 
71 
     | 
    
         | 
| 
       72 
72 
     | 
    
         
             
                    a = Thrift::Bytes.convert_to_utf8_byte_buffer e
         
     | 
| 
       73 
     | 
    
         
            -
                    a.encoding. 
     | 
| 
       74 
     | 
    
         
            -
                    a.length. 
     | 
| 
       75 
     | 
    
         
            -
                    a.unpack('C*'). 
     | 
| 
      
 73 
     | 
    
         
            +
                    expect(a.encoding).to eq(Encoding::BINARY)
         
     | 
| 
      
 74 
     | 
    
         
            +
                    expect(a.length).to eq(3)
         
     | 
| 
      
 75 
     | 
    
         
            +
                    expect(a.unpack('C*')).to eq([0xE2, 0x82, 0xAC])
         
     | 
| 
       76 
76 
     | 
    
         
             
                  end
         
     | 
| 
       77 
77 
     | 
    
         | 
| 
       78 
78 
     | 
    
         
             
                  it 'should convert ISO-8859-15 String to UTF-8 byte buffer' do
         
     | 
| 
       79 
79 
     | 
    
         
             
                    # Assumptions
         
     | 
| 
       80 
80 
     | 
    
         
             
                    e = "\u20AC".encode('ISO-8859-15') # a string with euro sign character U+20AC, then converted to ISO-8859-15
         
     | 
| 
       81 
     | 
    
         
            -
                    e.length. 
     | 
| 
       82 
     | 
    
         
            -
                    e.unpack('C*'). 
     | 
| 
      
 81 
     | 
    
         
            +
                    expect(e.length).to eq(1)
         
     | 
| 
      
 82 
     | 
    
         
            +
                    expect(e.unpack('C*')).to eq([0xA4]) # euro sign is a different code point in ISO-8859-15
         
     | 
| 
       83 
83 
     | 
    
         | 
| 
       84 
84 
     | 
    
         
             
                    a = Thrift::Bytes.convert_to_utf8_byte_buffer e
         
     | 
| 
       85 
     | 
    
         
            -
                    a.encoding. 
     | 
| 
       86 
     | 
    
         
            -
                    a.length. 
     | 
| 
       87 
     | 
    
         
            -
                    a.unpack('C*'). 
     | 
| 
      
 85 
     | 
    
         
            +
                    expect(a.encoding).to eq(Encoding::BINARY)
         
     | 
| 
      
 86 
     | 
    
         
            +
                    expect(a.length).to eq(3)
         
     | 
| 
      
 87 
     | 
    
         
            +
                    expect(a.unpack('C*')).to eq([0xE2, 0x82, 0xAC])
         
     | 
| 
       88 
88 
     | 
    
         
             
                  end
         
     | 
| 
       89 
89 
     | 
    
         
             
                end
         
     | 
| 
       90 
90 
     | 
    
         | 
| 
       91 
91 
     | 
    
         
             
                describe '.convert_to_string' do
         
     | 
| 
       92 
92 
     | 
    
         
             
                  it 'should convert UTF-8 byte buffer to a UTF-8 String' do
         
     | 
| 
       93 
93 
     | 
    
         
             
                    e = [0xE2, 0x82, 0xAC].pack("C*")
         
     | 
| 
       94 
     | 
    
         
            -
                    e.encoding. 
     | 
| 
      
 94 
     | 
    
         
            +
                    expect(e.encoding).to eq(Encoding::BINARY)
         
     | 
| 
       95 
95 
     | 
    
         
             
                    a = Thrift::Bytes.convert_to_string e
         
     | 
| 
       96 
     | 
    
         
            -
                    a.encoding. 
     | 
| 
       97 
     | 
    
         
            -
                    a. 
     | 
| 
      
 96 
     | 
    
         
            +
                    expect(a.encoding).to eq(Encoding::UTF_8)
         
     | 
| 
      
 97 
     | 
    
         
            +
                    expect(a).to eq("\u20AC")
         
     | 
| 
       98 
98 
     | 
    
         
             
                  end
         
     | 
| 
       99 
99 
     | 
    
         
             
                end
         
     | 
| 
       100 
100 
     | 
    
         | 
| 
         @@ -102,14 +102,14 @@ describe Thrift::Bytes do 
     | 
|
| 
       102 
102 
     | 
    
         
             
                describe '.empty_byte_buffer' do
         
     | 
| 
       103 
103 
     | 
    
         
             
                  it 'should create an empty buffer' do
         
     | 
| 
       104 
104 
     | 
    
         
             
                    b = Thrift::Bytes.empty_byte_buffer
         
     | 
| 
       105 
     | 
    
         
            -
                    b.length. 
     | 
| 
      
 105 
     | 
    
         
            +
                    expect(b.length).to eq(0)
         
     | 
| 
       106 
106 
     | 
    
         
             
                  end
         
     | 
| 
       107 
107 
     | 
    
         | 
| 
       108 
108 
     | 
    
         
             
                  it 'should create an empty buffer of given size' do
         
     | 
| 
       109 
109 
     | 
    
         
             
                    b = Thrift::Bytes.empty_byte_buffer 2
         
     | 
| 
       110 
     | 
    
         
            -
                    b.length. 
     | 
| 
       111 
     | 
    
         
            -
                    b[0]. 
     | 
| 
       112 
     | 
    
         
            -
                    b[1]. 
     | 
| 
      
 110 
     | 
    
         
            +
                    expect(b.length).to eq(2)
         
     | 
| 
      
 111 
     | 
    
         
            +
                    expect(b[0]).to eq(0)
         
     | 
| 
      
 112 
     | 
    
         
            +
                    expect(b[1]).to eq(0)
         
     | 
| 
       113 
113 
     | 
    
         
             
                  end
         
     | 
| 
       114 
114 
     | 
    
         
             
                end
         
     | 
| 
       115 
115 
     | 
    
         | 
| 
         @@ -117,16 +117,16 @@ describe Thrift::Bytes do 
     | 
|
| 
       117 
117 
     | 
    
         
             
                  it 'should be a no-op' do
         
     | 
| 
       118 
118 
     | 
    
         
             
                    e = 'STRING'
         
     | 
| 
       119 
119 
     | 
    
         
             
                    a = Thrift::Bytes.force_binary_encoding e
         
     | 
| 
       120 
     | 
    
         
            -
                    a. 
     | 
| 
       121 
     | 
    
         
            -
                    a. 
     | 
| 
      
 120 
     | 
    
         
            +
                    expect(a).to eq(e)
         
     | 
| 
      
 121 
     | 
    
         
            +
                    expect(a).to be(e)
         
     | 
| 
       122 
122 
     | 
    
         
             
                  end
         
     | 
| 
       123 
123 
     | 
    
         
             
                end
         
     | 
| 
       124 
124 
     | 
    
         | 
| 
       125 
125 
     | 
    
         
             
                describe '.get_string_byte' do
         
     | 
| 
       126 
126 
     | 
    
         
             
                  it 'should get the byte at index' do
         
     | 
| 
       127 
127 
     | 
    
         
             
                    s = "\x41\x42"
         
     | 
| 
       128 
     | 
    
         
            -
                    Thrift::Bytes.get_string_byte(s, 0). 
     | 
| 
       129 
     | 
    
         
            -
                    Thrift::Bytes.get_string_byte(s, 1). 
     | 
| 
      
 128 
     | 
    
         
            +
                    expect(Thrift::Bytes.get_string_byte(s, 0)).to eq(0x41)
         
     | 
| 
      
 129 
     | 
    
         
            +
                    expect(Thrift::Bytes.get_string_byte(s, 1)).to eq(0x42)
         
     | 
| 
       130 
130 
     | 
    
         
             
                  end
         
     | 
| 
       131 
131 
     | 
    
         
             
                end
         
     | 
| 
       132 
132 
     | 
    
         | 
| 
         @@ -134,8 +134,8 @@ describe Thrift::Bytes do 
     | 
|
| 
       134 
134 
     | 
    
         
             
                  it 'should set byte value at index' do
         
     | 
| 
       135 
135 
     | 
    
         
             
                    s = "\x41\x42"
         
     | 
| 
       136 
136 
     | 
    
         
             
                    Thrift::Bytes.set_string_byte(s, 0, 0x43)
         
     | 
| 
       137 
     | 
    
         
            -
                    s[0]. 
     | 
| 
       138 
     | 
    
         
            -
                    s. 
     | 
| 
      
 137 
     | 
    
         
            +
                    expect(s[0]).to eq(0x43)
         
     | 
| 
      
 138 
     | 
    
         
            +
                    expect(s).to eq('CB')
         
     | 
| 
       139 
139 
     | 
    
         
             
                  end
         
     | 
| 
       140 
140 
     | 
    
         
             
                end
         
     | 
| 
       141 
141 
     | 
    
         | 
| 
         @@ -143,8 +143,8 @@ describe Thrift::Bytes do 
     | 
|
| 
       143 
143 
     | 
    
         
             
                  it 'should be a no-op' do
         
     | 
| 
       144 
144 
     | 
    
         
             
                    e = 'STRING'
         
     | 
| 
       145 
145 
     | 
    
         
             
                    a = Thrift::Bytes.convert_to_utf8_byte_buffer e
         
     | 
| 
       146 
     | 
    
         
            -
                    a. 
     | 
| 
       147 
     | 
    
         
            -
                    a. 
     | 
| 
      
 146 
     | 
    
         
            +
                    expect(a).to eq(e)
         
     | 
| 
      
 147 
     | 
    
         
            +
                    expect(a).to be(e)
         
     | 
| 
       148 
148 
     | 
    
         
             
                  end
         
     | 
| 
       149 
149 
     | 
    
         
             
                end
         
     | 
| 
       150 
150 
     | 
    
         | 
| 
         @@ -152,8 +152,8 @@ describe Thrift::Bytes do 
     | 
|
| 
       152 
152 
     | 
    
         
             
                  it 'should be a no-op' do
         
     | 
| 
       153 
153 
     | 
    
         
             
                    e = 'STRING'
         
     | 
| 
       154 
154 
     | 
    
         
             
                    a = Thrift::Bytes.convert_to_string e
         
     | 
| 
       155 
     | 
    
         
            -
                    a. 
     | 
| 
       156 
     | 
    
         
            -
                    a. 
     | 
| 
      
 155 
     | 
    
         
            +
                    expect(a).to eq(e)
         
     | 
| 
      
 156 
     | 
    
         
            +
                    expect(a).to be(e)
         
     | 
| 
       157 
157 
     | 
    
         
             
                  end
         
     | 
| 
       158 
158 
     | 
    
         
             
                end
         
     | 
| 
       159 
159 
     | 
    
         
             
              end
         
     |