Skip to content
This repository
Browse code

BinUtils for response

  • Loading branch information...
commit 2c47693148bdee60c9441ad06a62ea0996f997a1 1 parent 1327d46
Sokolov Yura authored August 06, 2012

Showing 1 changed file with 19 additions and 18 deletions. Show diff stats Hide diff stats

  1. 37  lib/tarantool/response.rb
37  lib/tarantool/response.rb
... ...
@@ -1,3 +1,4 @@
  1
+require 'bin_utils'
1 2
 require 'tarantool/util'
2 3
 require 'tarantool/exceptions'
3 4
 require 'tarantool/serializers'
@@ -8,7 +9,7 @@ module ParseIProto
8 9
     def _parse_iproto(data)
9 10
       if Exception === data || data == ''
10 11
         data
11  
-      elsif (ret = unpack_int32!(data)) == 0
  12
+      elsif (ret = ::BinUtils.slice_int32_le!(data)) == 0
12 13
         data
13 14
       else
14 15
         data.gsub!("\x00", "")
@@ -47,7 +48,7 @@ def call_callback(result)
47 48
     def parse_response(data)
48 49
       return data  if Exception === data
49 50
       unless get_tuples
50  
-        unpack_int32(data)
  51
+        ::BinUtils.get_int32_le(data)
51 52
       else
52 53
         tuples = unpack_tuples(data)
53 54
         if translators
@@ -60,7 +61,7 @@ def parse_response(data)
60 61
     end
61 62
 
62 63
     def unpack_tuples(data)
63  
-      tuples_affected = unpack_int32!(data)
  64
+      tuples_affected = ::BinUtils.slice_int32_le!(data)
64 65
       tuples = []
65 66
       fields = fields()
66 67
       if Integer === fields.last
@@ -70,13 +71,13 @@ def unpack_tuples(data)
70 71
       end
71 72
 
72 73
       while tuples_affected > 0
73  
-        byte_size = unpack_int32!(data)
74  
-        fields_num = unpack_int32!(data)
  74
+        byte_size = ::BinUtils.slice_int32_le!(data)
  75
+        fields_num = ::BinUtils.slice_int32_le!(data)
75 76
         tuple_str = data.slice!(0, byte_size)
76 77
         i = 0
77 78
         tuple = []
78 79
         while i < fields_num
79  
-          field_size = unpack_ber!(tuple_str)
  80
+          field_size = ::BinUtils.slice_ber!(tuple_str)
80 81
 
81 82
           field = fields[i] || get_tail_item(fields, i, tail)
82 83
 
@@ -86,7 +87,7 @@ def unpack_tuples(data)
86 87
               if field_size != 4
87 88
                 raise ValueError, "Bad field size #{field_size} for integer field ##{i}"
88 89
               end
89  
-              unpack_int32!(tuple_str)
  90
+              ::BinUtils.slice_int32_le!(tuple_str)
90 91
             when :string, :str
91 92
               str = tuple_str.slice!(0, field_size)
92 93
               str[0,1] = EMPTY  if str < ONE
@@ -95,47 +96,47 @@ def unpack_tuples(data)
95 96
               if field_size != 8
96 97
                 raise ValueError, "Bad field size #{field_size} for 64bit integer field ##{i}"
97 98
               end
98  
-              unpack_int64!(tuple_str)
  99
+              ::BinUtils.slice_int64_le!(tuple_str)
99 100
             when :bytes
100 101
               tuple_str.slice!(0, field_size)
101 102
             when :int16
102 103
               if field_size != 2
103 104
                 raise ValueError, "Bad field size #{field_size} for 16bit integer field ##{i}"
104 105
               end
105  
-              unpack_int16!(tuple_str)
  106
+              ::BinUtils.slice_int16_le!(tuple_str)
106 107
             when :int8
107 108
               if field_size != 1
108 109
                 raise ValueError, "Bad field size #{field_size} for 8bit integer field ##{i}"
109 110
               end
110  
-              unpack_int8!(tuple_str)
  111
+              ::BinUtils.slice_int8!(tuple_str)
111 112
             when :sint
112 113
               if field_size != 4
113 114
                 raise ValueError, "Bad field size #{field_size} for integer field ##{i}"
114 115
               end
115  
-              unpack_sint32!(tuple_str)
  116
+              ::BinUtils.slice_sint32_le!(tuple_str)
116 117
             when :sint64
117 118
               if field_size != 8
118 119
                 raise ValueError, "Bad field size #{field_size} for 64bit integer field ##{i}"
119 120
               end
120  
-              unpack_sint64!(tuple_str)
  121
+              ::BinUtils.slice_sint64_le!(tuple_str)
121 122
             when :sint16
122 123
               if field_size != 2
123 124
                 raise ValueError, "Bad field size #{field_size} for 16bit integer field ##{i}"
124 125
               end
125  
-              unpack_sint16!(tuple_str)
  126
+              ::BinUtils.slice_sint16_le!(tuple_str)
126 127
             when :sint8
127 128
               if field_size != 1
128 129
                 raise ValueError, "Bad field size #{field_size} for 8bit integer field ##{i}"
129 130
               end
130  
-              unpack_sint8!(tuple_str)
  131
+              ::BinUtils.slice_sint8!(tuple_str)
131 132
             when :varint
132 133
               case field_size
133 134
               when 8
134  
-                unpack_int64!(tuple_str)
  135
+                ::BinUtils.slice_int64_le!(tuple_str)
135 136
               when 4
136  
-                unpack_int32!(tuple_str)
  137
+                ::BinUtils.slice_int32_le!(tuple_str)
137 138
               when 2
138  
-                unpack_int16!(tuple_str)
  139
+                ::BinUtils.slice_int16_le!(tuple_str)
139 140
               else
140 141
                 raise ValueError, "Bad field size #{field_size} for integer field ##{i}"
141 142
               end
@@ -159,7 +160,7 @@ def unpack_tuples(data)
159 160
     end
160 161
 
161 162
     def return_code(data)
162  
-      unpack_int32!(data)
  163
+      ::BinUtils.slice_int32_le!(data)
163 164
     end
164 165
   end
165 166
 

0 notes on commit 2c47693

Please sign in to comment.
Something went wrong with that request. Please try again.