@@ -65,6 +65,11 @@ def __init__(self, conn):
65
65
self ._sync = None
66
66
self ._body = ''
67
67
68
+ self .packer = msgpack .Packer ()
69
+
70
+ def _dumps (self , src ):
71
+ return self .packer .pack (src )
72
+
68
73
def __bytes__ (self ):
69
74
return self .header (len (self ._body )) + self ._body
70
75
@@ -82,11 +87,11 @@ def sync(self):
82
87
83
88
def header (self , length ):
84
89
self ._sync = self .conn .generate_sync ()
85
- header = msgpack . dumps ({IPROTO_CODE : self .request_type ,
86
- IPROTO_SYNC : self ._sync ,
87
- IPROTO_SCHEMA_ID : self .conn .schema_version })
90
+ header = self . _dumps ({IPROTO_CODE : self .request_type ,
91
+ IPROTO_SYNC : self ._sync ,
92
+ IPROTO_SCHEMA_ID : self .conn .schema_version })
88
93
89
- return msgpack . dumps (length + len (header )) + header
94
+ return self . _dumps (length + len (header )) + header
90
95
91
96
92
97
class RequestInsert (Request ):
@@ -102,8 +107,8 @@ def __init__(self, conn, space_no, values):
102
107
super (RequestInsert , self ).__init__ (conn )
103
108
assert isinstance (values , (tuple , list ))
104
109
105
- request_body = msgpack . dumps ({IPROTO_SPACE_ID : space_no ,
106
- IPROTO_TUPLE : values })
110
+ request_body = self . _dumps ({IPROTO_SPACE_ID : space_no ,
111
+ IPROTO_TUPLE : values })
107
112
108
113
self ._body = request_body
109
114
@@ -131,19 +136,19 @@ def sha1(values):
131
136
hash2 = sha1 ((hash1 ,))
132
137
scramble = sha1 ((salt , hash2 ))
133
138
scramble = strxor (hash1 , scramble )
134
- request_body = msgpack . dumps ({IPROTO_USER_NAME : user ,
135
- IPROTO_TUPLE : ("chap-sha1" , scramble )})
139
+ request_body = self . _dumps ({IPROTO_USER_NAME : user ,
140
+ IPROTO_TUPLE : ("chap-sha1" , scramble )})
136
141
self ._body = request_body
137
142
138
143
def header (self , length ):
139
144
self ._sync = self .conn .generate_sync ()
140
145
# Set IPROTO_SCHEMA_ID: 0 to avoid SchemaReloadException
141
146
# It is ok to use 0 in auth every time.
142
- header = msgpack . dumps ({IPROTO_CODE : self .request_type ,
143
- IPROTO_SYNC : self ._sync ,
144
- IPROTO_SCHEMA_ID : 0 })
147
+ header = self . _dumps ({IPROTO_CODE : self .request_type ,
148
+ IPROTO_SYNC : self ._sync ,
149
+ IPROTO_SCHEMA_ID : 0 })
145
150
146
- return msgpack . dumps (length + len (header )) + header
151
+ return self . _dumps (length + len (header )) + header
147
152
148
153
149
154
class RequestReplace (Request ):
@@ -159,8 +164,8 @@ def __init__(self, conn, space_no, values):
159
164
super (RequestReplace , self ).__init__ (conn )
160
165
assert isinstance (values , (tuple , list ))
161
166
162
- request_body = msgpack . dumps ({IPROTO_SPACE_ID : space_no ,
163
- IPROTO_TUPLE : values })
167
+ request_body = self . _dumps ({IPROTO_SPACE_ID : space_no ,
168
+ IPROTO_TUPLE : values })
164
169
165
170
self ._body = request_body
166
171
@@ -177,9 +182,9 @@ def __init__(self, conn, space_no, index_no, key):
177
182
'''
178
183
super (RequestDelete , self ).__init__ (conn )
179
184
180
- request_body = msgpack . dumps ({IPROTO_SPACE_ID : space_no ,
181
- IPROTO_INDEX_ID : index_no ,
182
- IPROTO_KEY : key })
185
+ request_body = self . _dumps ({IPROTO_SPACE_ID : space_no ,
186
+ IPROTO_INDEX_ID : index_no ,
187
+ IPROTO_KEY : key })
183
188
184
189
self ._body = request_body
185
190
@@ -193,12 +198,12 @@ class RequestSelect(Request):
193
198
# pylint: disable=W0231
194
199
def __init__ (self , conn , space_no , index_no , key , offset , limit , iterator ):
195
200
super (RequestSelect , self ).__init__ (conn )
196
- request_body = msgpack . dumps ({IPROTO_SPACE_ID : space_no ,
197
- IPROTO_INDEX_ID : index_no ,
198
- IPROTO_OFFSET : offset ,
199
- IPROTO_LIMIT : limit ,
200
- IPROTO_ITERATOR : iterator ,
201
- IPROTO_KEY : key })
201
+ request_body = self . _dumps ({IPROTO_SPACE_ID : space_no ,
202
+ IPROTO_INDEX_ID : index_no ,
203
+ IPROTO_OFFSET : offset ,
204
+ IPROTO_LIMIT : limit ,
205
+ IPROTO_ITERATOR : iterator ,
206
+ IPROTO_KEY : key })
202
207
203
208
self ._body = request_body
204
209
@@ -214,10 +219,10 @@ class RequestUpdate(Request):
214
219
def __init__ (self , conn , space_no , index_no , key , op_list ):
215
220
super (RequestUpdate , self ).__init__ (conn )
216
221
217
- request_body = msgpack . dumps ({IPROTO_SPACE_ID : space_no ,
218
- IPROTO_INDEX_ID : index_no ,
219
- IPROTO_KEY : key ,
220
- IPROTO_TUPLE : op_list })
222
+ request_body = self . _dumps ({IPROTO_SPACE_ID : space_no ,
223
+ IPROTO_INDEX_ID : index_no ,
224
+ IPROTO_KEY : key ,
225
+ IPROTO_TUPLE : op_list })
221
226
222
227
self ._body = request_body
223
228
@@ -235,8 +240,8 @@ def __init__(self, conn, name, args, call_16):
235
240
super (RequestCall , self ).__init__ (conn )
236
241
assert isinstance (args , (list , tuple ))
237
242
238
- request_body = msgpack . dumps ({IPROTO_FUNCTION_NAME : name ,
239
- IPROTO_TUPLE : args })
243
+ request_body = self . _dumps ({IPROTO_FUNCTION_NAME : name ,
244
+ IPROTO_TUPLE : args })
240
245
241
246
self ._body = request_body
242
247
@@ -252,8 +257,8 @@ def __init__(self, conn, name, args):
252
257
super (RequestEval , self ).__init__ (conn )
253
258
assert isinstance (args , (list , tuple ))
254
259
255
- request_body = msgpack . dumps ({IPROTO_EXPR : name ,
256
- IPROTO_TUPLE : args })
260
+ request_body = self . _dumps ({IPROTO_EXPR : name ,
261
+ IPROTO_TUPLE : args })
257
262
258
263
self ._body = request_body
259
264
@@ -280,10 +285,10 @@ class RequestUpsert(Request):
280
285
def __init__ (self , conn , space_no , index_no , tuple_value , op_list ):
281
286
super (RequestUpsert , self ).__init__ (conn )
282
287
283
- request_body = msgpack . dumps ({IPROTO_SPACE_ID : space_no ,
284
- IPROTO_INDEX_ID : index_no ,
285
- IPROTO_TUPLE : tuple_value ,
286
- IPROTO_OPS : op_list })
288
+ request_body = self . _dumps ({IPROTO_SPACE_ID : space_no ,
289
+ IPROTO_INDEX_ID : index_no ,
290
+ IPROTO_TUPLE : tuple_value ,
291
+ IPROTO_OPS : op_list })
287
292
288
293
self ._body = request_body
289
294
@@ -297,7 +302,7 @@ class RequestJoin(Request):
297
302
# pylint: disable=W0231
298
303
def __init__ (self , conn , server_uuid ):
299
304
super (RequestJoin , self ).__init__ (conn )
300
- request_body = msgpack . dumps ({IPROTO_SERVER_UUID : server_uuid })
305
+ request_body = self . _dumps ({IPROTO_SERVER_UUID : server_uuid })
301
306
self ._body = request_body
302
307
303
308
@@ -312,7 +317,7 @@ def __init__(self, conn, cluster_uuid, server_uuid, vclock):
312
317
super (RequestSubscribe , self ).__init__ (conn )
313
318
assert isinstance (vclock , dict )
314
319
315
- request_body = msgpack . dumps ({
320
+ request_body = self . _dumps ({
316
321
IPROTO_CLUSTER_UUID : cluster_uuid ,
317
322
IPROTO_SERVER_UUID : server_uuid ,
318
323
IPROTO_VCLOCK : vclock
@@ -329,6 +334,6 @@ class RequestOK(Request):
329
334
# pylint: disable=W0231
330
335
def __init__ (self , conn , sync ):
331
336
super (RequestOK , self ).__init__ (conn )
332
- request_body = msgpack . dumps ({IPROTO_CODE : self .request_type ,
333
- IPROTO_SYNC : sync })
337
+ request_body = self . _dumps ({IPROTO_CODE : self .request_type ,
338
+ IPROTO_SYNC : sync })
334
339
self ._body = request_body
0 commit comments