tarantool 0.4.2.1 → 0.4.3

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.
@@ -83,7 +83,7 @@ module Tarantool
83
83
  if index_no != :space && nili = key.index(nil)
84
84
  key = key.slice(0, nili)
85
85
  end
86
- body << [key_size = key.size].pack(INT32)
86
+ ::BinUtils.append_int32_le!(body, key_size = key.size)
87
87
  i = 0
88
88
  while i < key_size
89
89
  field = types[i] || get_tail_item(types, i, tail)
@@ -110,50 +110,50 @@ module Tarantool
110
110
  when :int, :integer
111
111
  value = value.to_i
112
112
  _raise_integer_overflow(value, MIN_INT, MAX_INT32) if value > MAX_INT32 or value < 0
113
- append_ber_int32!(body, value)
113
+ ::BinUtils.append_bersize_int32_le!(body, value)
114
114
  when :string, :bytes, :str
115
115
  value = value.to_s
116
116
  value = ZERO + value if value < ONE
117
117
  raise StringTooLong if value.bytesize >= MAX_BYTE_SIZE
118
- body << [value.bytesize, value].pack(PACK_STRING)
118
+ ::BinUtils.append_bersize_string!(body, value)
119
119
  when :bytes
120
120
  value = value.to_s
121
121
  raise StringTooLong if value.bytesize >= MAX_BYTE_SIZE
122
- body << [value.bytesize, value].pack(PACK_STRING)
122
+ ::BinUtils.append_bersize_string!(body, value)
123
123
  when :int64
124
124
  value = value.to_i
125
125
  _raise_integer_overflow(value, MIN_INT, MAX_INT64) if value > MAX_INT64 or value < 0
126
- append_ber_int64!(body, value)
126
+ ::BinUtils.append_bersize_int64_le!(body, value)
127
127
  when :int16
128
128
  value = value.to_i
129
129
  _raise_integer_overflow(value, MIN_INT, MAX_INT16) if value > MAX_INT16 or value < 0
130
- append_ber_int16!(body, value)
130
+ ::BinUtils.append_bersize_int16_le!(body, value)
131
131
  when :int8
132
132
  value = value.to_i
133
133
  _raise_integer_overflow(value, MIN_INT, MAX_INT8) if value > MAX_INT8 or value < 0
134
- append_ber_int8!(body, value)
134
+ ::BinUtils.append_bersize_int8!(body, value)
135
135
  when :sint
136
136
  value = value.to_i
137
137
  _raise_integer_overflow(value, MIN_SINT32, MAX_SINT32) if value > MAX_SINT32 or value < MIN_SINT32
138
- append_ber_sint32!(body, value)
138
+ ::BinUtils.append_bersize_sint32_le!(body, value)
139
139
  when :sint64
140
140
  value = value.to_i
141
141
  _raise_integer_overflow(value, MIN_SINT64, MAX_SINT64) if value > MAX_SINT64 or value < MIN_SINT64
142
- append_ber_sint64!(body, value)
142
+ ::BinUtils.append_bersize_sint64_le!(body, value)
143
143
  when :sint16
144
144
  value = value.to_i
145
145
  _raise_integer_overflow(value, MIN_SINT16, MAX_SINT16) if value > MAX_SINT16 or value < MIN_SINT16
146
- append_ber_sint16!(body, value)
146
+ ::BinUtils.append_bersize_sint16_le!(body, value)
147
147
  when :sint8
148
148
  value = value.to_i
149
149
  _raise_integer_overflow(value, MIN_SINT8, MAX_SINT8) if value > MAX_SINT8 or value < MIN_SINT8
150
- append_ber_sint8!(body, value)
150
+ ::BinUtils.append_bersize_sint8!(body, value)
151
151
  when :varint
152
152
  value = value.to_i
153
153
  if 0 <= value && value < MAX_INT32
154
- append_ber_int32!(body, value)
154
+ ::BinUtils.append_bersize_int32_le!(body, value)
155
155
  else
156
- append_ber_sint64!(body, value)
156
+ ::BinUtils.append_bersize_sint64_le!(body, value)
157
157
  end
158
158
  when :error
159
159
  raise IndexIndexError
@@ -171,7 +171,7 @@ module Tarantool
171
171
  else
172
172
  value = get_serializer(field_kind).encode(value).to_s
173
173
  raise StringTooLong if value.bytesize > MAX_BYTE_SIZE
174
- body << [value.bytesize, value].pack(PACK_STRING)
174
+ ::BinUtils.append_bersize_string!(body, value)
175
175
  end
176
176
  end
177
177
 
@@ -206,7 +206,7 @@ module Tarantool
206
206
 
207
207
  body = [space_no, flags].pack(UPDATE_HEADER)
208
208
  pack_tuple(body, pk, pk_fields, 0)
209
- append_int32!(body, operations.size)
209
+ ::BinUtils.append_int32_le!(body, operations.size)
210
210
 
211
211
  _pack_operations(body, operations, fields)
212
212
 
@@ -276,10 +276,10 @@ module Tarantool
276
276
  end
277
277
 
278
278
  str = operation[4].to_s
279
- body << [ 10 + ber_size(str.bytesize) + str.bytesize ].pack('w')
280
- append_ber_sint32!(body, operation[2].to_i)
281
- append_ber_sint32!(body, operation[3].to_i)
282
- body << [str.bytesize, str.to_s].pack(PACK_STRING)
279
+ ::BinUtils.append_ber!(body, 10 + ber_size(str.bytesize) + str.bytesize)
280
+ ::BinUtils.append_bersize_sint32_le!(body, operation[2].to_i)
281
+ ::BinUtils.append_bersize_sint32_le!(body, operation[3].to_i)
282
+ ::BinUtils.append_bersize_string!(body, str.to_s)
283
283
  when 7
284
284
  old_field_no = field_no +
285
285
  (inserted ||= []).count{|i| i <= field_no} -
@@ -8,7 +8,7 @@ module Tarantool
8
8
  def _parse_iproto(data)
9
9
  if Exception === data || data == ''
10
10
  data
11
- elsif (ret = unpack_int32!(data)) == 0
11
+ elsif (ret = ::BinUtils.slice_int32_le!(data)) == 0
12
12
  data
13
13
  else
14
14
  data.gsub!("\x00", "")
@@ -47,7 +47,7 @@ module Tarantool
47
47
  def parse_response(data)
48
48
  return data if Exception === data
49
49
  unless get_tuples
50
- unpack_int32(data)
50
+ ::BinUtils.get_int32_le(data)
51
51
  else
52
52
  tuples = unpack_tuples(data)
53
53
  if translators
@@ -60,7 +60,7 @@ module Tarantool
60
60
  end
61
61
 
62
62
  def unpack_tuples(data)
63
- tuples_affected = unpack_int32!(data)
63
+ tuples_affected = ::BinUtils.slice_int32_le!(data)
64
64
  tuples = []
65
65
  fields = fields()
66
66
  if Integer === fields.last
@@ -70,13 +70,13 @@ module Tarantool
70
70
  end
71
71
 
72
72
  while tuples_affected > 0
73
- byte_size = unpack_int32!(data)
74
- fields_num = unpack_int32!(data)
73
+ byte_size = ::BinUtils.slice_int32_le!(data)
74
+ fields_num = ::BinUtils.slice_int32_le!(data)
75
75
  tuple_str = data.slice!(0, byte_size)
76
76
  i = 0
77
77
  tuple = []
78
78
  while i < fields_num
79
- field_size = unpack_ber!(tuple_str)
79
+ field_size = ::BinUtils.slice_ber!(tuple_str)
80
80
 
81
81
  field = fields[i] || get_tail_item(fields, i, tail)
82
82
 
@@ -86,7 +86,7 @@ module Tarantool
86
86
  if field_size != 4
87
87
  raise ValueError, "Bad field size #{field_size} for integer field ##{i}"
88
88
  end
89
- unpack_int32!(tuple_str)
89
+ ::BinUtils.slice_int32_le!(tuple_str)
90
90
  when :string, :str
91
91
  str = tuple_str.slice!(0, field_size)
92
92
  str[0,1] = EMPTY if str < ONE
@@ -95,47 +95,47 @@ module Tarantool
95
95
  if field_size != 8
96
96
  raise ValueError, "Bad field size #{field_size} for 64bit integer field ##{i}"
97
97
  end
98
- unpack_int64!(tuple_str)
98
+ ::BinUtils.slice_int64_le!(tuple_str)
99
99
  when :bytes
100
100
  tuple_str.slice!(0, field_size)
101
101
  when :int16
102
102
  if field_size != 2
103
103
  raise ValueError, "Bad field size #{field_size} for 16bit integer field ##{i}"
104
104
  end
105
- unpack_int16!(tuple_str)
105
+ ::BinUtils.slice_int16_le!(tuple_str)
106
106
  when :int8
107
107
  if field_size != 1
108
108
  raise ValueError, "Bad field size #{field_size} for 8bit integer field ##{i}"
109
109
  end
110
- unpack_int8!(tuple_str)
110
+ ::BinUtils.slice_int8!(tuple_str)
111
111
  when :sint
112
112
  if field_size != 4
113
113
  raise ValueError, "Bad field size #{field_size} for integer field ##{i}"
114
114
  end
115
- unpack_sint32!(tuple_str)
115
+ ::BinUtils.slice_sint32_le!(tuple_str)
116
116
  when :sint64
117
117
  if field_size != 8
118
118
  raise ValueError, "Bad field size #{field_size} for 64bit integer field ##{i}"
119
119
  end
120
- unpack_sint64!(tuple_str)
120
+ ::BinUtils.slice_sint64_le!(tuple_str)
121
121
  when :sint16
122
122
  if field_size != 2
123
123
  raise ValueError, "Bad field size #{field_size} for 16bit integer field ##{i}"
124
124
  end
125
- unpack_sint16!(tuple_str)
125
+ ::BinUtils.slice_sint16_le!(tuple_str)
126
126
  when :sint8
127
127
  if field_size != 1
128
128
  raise ValueError, "Bad field size #{field_size} for 8bit integer field ##{i}"
129
129
  end
130
- unpack_sint8!(tuple_str)
130
+ ::BinUtils.slice_sint8!(tuple_str)
131
131
  when :varint
132
132
  case field_size
133
133
  when 8
134
- unpack_int64!(tuple_str)
134
+ ::BinUtils.slice_int64_le!(tuple_str)
135
135
  when 4
136
- unpack_int32!(tuple_str)
136
+ ::BinUtils.slice_int32_le!(tuple_str)
137
137
  when 2
138
- unpack_int16!(tuple_str)
138
+ ::BinUtils.slice_int16_le!(tuple_str)
139
139
  else
140
140
  raise ValueError, "Bad field size #{field_size} for integer field ##{i}"
141
141
  end
@@ -159,7 +159,7 @@ module Tarantool
159
159
  end
160
160
 
161
161
  def return_code(data)
162
- unpack_int32!(data)
162
+ ::BinUtils.slice_int32_le!(data)
163
163
  end
164
164
  end
165
165
 
@@ -1,3 +1,4 @@
1
+ require 'bin_utils'
1
2
  module Tarantool
2
3
  module Util
3
4
  module Packer
@@ -25,131 +26,12 @@ module Tarantool
25
26
  private
26
27
  EMPTY = ''.freeze
27
28
  ONE = "\x01".freeze
28
- def unpack_int8!(data)
29
- int = data.getbyte(0)
30
- data[0, 1] = EMPTY
31
- int
32
- end
33
-
34
- def unpack_int16(data)
35
- data.getbyte(0) + data.getbyte(1) * 256
36
- end
37
-
38
- def unpack_int16!(data)
39
- int = data.getbyte(0) + data.getbyte(1) * 256
40
- data[0, 2] = EMPTY
41
- int
42
- end
43
-
44
- def unpack_int32(int)
45
- (int.getbyte(0) + int.getbyte(1) * 256 +
46
- int.getbyte(2) * 65536 + int.getbyte(3) * 16777216)
47
- end
48
-
49
- def unpack_int32!(data)
50
- int = (data.getbyte(0) + data.getbyte(1) * 256 +
51
- data.getbyte(2) * 65536 + data.getbyte(3) * 16777216)
52
- data[0, 4] = EMPTY
53
- int
54
- end
55
-
56
- def unpack_int64!(data)
57
- int = data.unpack(INT64)[0]
58
- data[0, 8] = EMPTY
59
- int
60
- end
61
-
62
- def unpack_int64(data)
63
- data.unpack(INT64)[0]
64
- end
65
-
66
- def unpack_sint8!(data)
67
- i = unpack_int8!(data)
68
- i - ((i & 128) << 1)
69
- end
70
-
71
- def unpack_sint16!(data)
72
- i = unpack_int16!(data)
73
- i - ((i & 32768) << 1)
74
- end
75
-
76
- def unpack_sint32!(data)
77
- i = unpack_int32!(data)
78
- i - ((i >> 31) << 32)
79
- end
80
-
81
- def unpack_sint64!(data)
82
- i = unpack_int64!(data)
83
- i - ((i >> 63) << 64)
84
- end
85
-
86
29
  def ber_size(int)
87
30
  int < 128 ? 1 :
88
31
  int < 16384 ? 2 :
89
32
  int < 2097153 ? 3 :
90
33
  int < 268435456 ? 4 : 5
91
34
  end
92
-
93
- def unpack_ber!(data)
94
- res = 0
95
- pos = 0
96
- while true
97
- if (byte = data.getbyte(pos)) <= 127
98
- res += byte
99
- break
100
- else
101
- res = (res + (byte - 128)) * 128
102
- pos += 1
103
- end
104
- end
105
- data[0, pos+1] = EMPTY
106
- res
107
- end
108
-
109
- def append_int8!(str, int)
110
- str << (int & 255)
111
- end
112
-
113
- def append_int16!(str, int)
114
- str << (int & 255) << ((int>>8) & 255)
115
- end
116
-
117
- def append_int32!(str, int)
118
- str << (int & 255) << ((int>>8) & 255) <<
119
- ((int>>16) & 255) << ((int>>24) & 255)
120
- end
121
-
122
- def append_int64!(str, int)
123
- str << [int].pack(INT64)
124
- end
125
-
126
- alias append_sint8! append_int8!
127
- alias append_sint16! append_int16!
128
- alias append_sint32! append_int32!
129
- alias append_sint64! append_int64!
130
-
131
- def append_ber_int8!(str, int)
132
- str << 1 << (int & 255)
133
- end
134
-
135
- def append_ber_int16!(str, int)
136
- str << 2 << (int & 255) << ((int>>8) & 255)
137
- end
138
-
139
- def append_ber_int32!(str, int)
140
- str << 4 <<
141
- (int & 255) << ((int>>8) & 255) <<
142
- ((int>>16) & 255) << ((int>>24) & 255)
143
- end
144
-
145
- def append_ber_int64!(str, int)
146
- str << 8 << [int].pack(INT64)
147
- end
148
-
149
- alias append_ber_sint8! append_ber_int8!
150
- alias append_ber_sint16! append_ber_int16!
151
- alias append_ber_sint32! append_ber_int32!
152
- alias append_ber_sint64! append_ber_int64!
153
35
  end
154
36
 
155
37
  module TailGetter
@@ -179,11 +61,11 @@ module Tarantool
179
61
  def to_int
180
62
  case @data.bytesize
181
63
  when 8
182
- unpack_int64(@data)
64
+ ::BinUtils.get_int64_le(@data)
183
65
  when 4
184
- unpack_int32(@data)
66
+ ::BinUtils.get_int32_le(@data)
185
67
  when 2
186
- unpack_int16(@data)
68
+ ::BinUtils.get_int16_le(@data)
187
69
  else
188
70
  raise ValueError, "Bad field size #{field_size} for integer field ##{i}"
189
71
  end
@@ -1,4 +1,4 @@
1
1
  module Tarantool
2
- VERSION = "0.4.2.1"
3
- RECORD_VERSION = "0.4.1.1"
2
+ VERSION = "0.4.3"
3
+ RECORD_VERSION = "0.4.1.2"
4
4
  end
@@ -3,12 +3,13 @@ require 'yajl'
3
3
  require 'tarantool/serializers/bson'
4
4
 
5
5
  shared_examples_for :record do
6
- DB = Tarantool.new(TCONFIG.merge(type: :block))
6
+ let(:db){ Tarantool.new(TCONFIG.merge(type: :block)) }
7
7
  before{ truncate }
8
8
 
9
9
  let(:user_class) do
10
+ db = db()
10
11
  Class.new(base_class) do
11
- set_tarantool DB
12
+ set_tarantool db
12
13
  set_space_no 0
13
14
 
14
15
  def self.name # For naming
@@ -24,8 +25,9 @@ shared_examples_for :record do
24
25
  end
25
26
 
26
27
  let(:second_class) do
28
+ db = db()
27
29
  Class.new(base_class) do
28
- set_tarantool DB
30
+ set_tarantool db
29
31
  set_space_no 1
30
32
 
31
33
  def self.name # For naming
@@ -360,13 +362,13 @@ shared_examples_for :record do
360
362
  second_class.insert(id: 100).must_equal 1
361
363
  obj = second_class.by_pk(100)
362
364
  obj.attributes.must_equal({id: 100, count1: nil, count2: nil})
363
- tuple = DB.space(1, [:int, :int, :int], keys: 0).by_pk(100)
365
+ tuple = db.space(1, [:int, :int, :int], keys: 0).by_pk(100)
364
366
  tuple.must_equal([100, nil, nil])
365
367
 
366
368
  second_class.insert(id: 101, count2: 102).must_equal 1
367
369
  obj = second_class.by_pk(101)
368
370
  obj.attributes.must_equal({id: 101, count1: nil, count2: 102})
369
- tuple = DB.space(1, [:int, :int, :int], keys: 0).by_pk(101)
371
+ tuple = db.space(1, [:int, :int, :int], keys: 0).by_pk(101)
370
372
  tuple.must_equal([101, nil, 102])
371
373
  end
372
374
 
@@ -474,8 +476,9 @@ shared_examples_for :record do
474
476
 
475
477
  describe "composite primary key" do
476
478
  let(:address_class) do
479
+ db = db()
477
480
  Class.new(base_class) do
478
- set_tarantool DB
481
+ set_tarantool db
479
482
  set_space_no 2
480
483
 
481
484
  def self.name # For naming
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tarantool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2.1
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-04 00:00:00.000000000 Z
13
+ date: 2012-08-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: iproto
@@ -60,6 +60,22 @@ dependencies:
60
60
  - - ! '>='
61
61
  - !ruby/object:Gem::Version
62
62
  version: 0.0.2
63
+ - !ruby/object:Gem::Dependency
64
+ name: bin_utils
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 0.0.1
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 0.0.1
63
79
  description: Tarantool KV-storage client.
64
80
  email:
65
81
  - ceo@prepor.ru