@@ -65,6 +65,11 @@ def __init__(self, conn):
6565 self ._sync = None
6666 self ._body = ''
6767
68+ self .packer = msgpack .Packer ()
69+
70+ def _dumps (self , src ):
71+ return self .packer .pack (src )
72+
6873 def __bytes__ (self ):
6974 return self .header (len (self ._body )) + self ._body
7075
@@ -82,11 +87,11 @@ def sync(self):
8287
8388 def header (self , length ):
8489 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 })
8893
89- return msgpack . dumps (length + len (header )) + header
94+ return self . _dumps (length + len (header )) + header
9095
9196
9297class RequestInsert (Request ):
@@ -102,8 +107,8 @@ def __init__(self, conn, space_no, values):
102107 super (RequestInsert , self ).__init__ (conn )
103108 assert isinstance (values , (tuple , list ))
104109
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 })
107112
108113 self ._body = request_body
109114
@@ -131,19 +136,19 @@ def sha1(values):
131136 hash2 = sha1 ((hash1 ,))
132137 scramble = sha1 ((salt , hash2 ))
133138 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 )})
136141 self ._body = request_body
137142
138143 def header (self , length ):
139144 self ._sync = self .conn .generate_sync ()
140145 # Set IPROTO_SCHEMA_ID: 0 to avoid SchemaReloadException
141146 # 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 })
145150
146- return msgpack . dumps (length + len (header )) + header
151+ return self . _dumps (length + len (header )) + header
147152
148153
149154class RequestReplace (Request ):
@@ -159,8 +164,8 @@ def __init__(self, conn, space_no, values):
159164 super (RequestReplace , self ).__init__ (conn )
160165 assert isinstance (values , (tuple , list ))
161166
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 })
164169
165170 self ._body = request_body
166171
@@ -177,9 +182,9 @@ def __init__(self, conn, space_no, index_no, key):
177182 '''
178183 super (RequestDelete , self ).__init__ (conn )
179184
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 })
183188
184189 self ._body = request_body
185190
@@ -193,12 +198,12 @@ class RequestSelect(Request):
193198 # pylint: disable=W0231
194199 def __init__ (self , conn , space_no , index_no , key , offset , limit , iterator ):
195200 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 })
202207
203208 self ._body = request_body
204209
@@ -214,10 +219,10 @@ class RequestUpdate(Request):
214219 def __init__ (self , conn , space_no , index_no , key , op_list ):
215220 super (RequestUpdate , self ).__init__ (conn )
216221
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 })
221226
222227 self ._body = request_body
223228
@@ -235,8 +240,8 @@ def __init__(self, conn, name, args, call_16):
235240 super (RequestCall , self ).__init__ (conn )
236241 assert isinstance (args , (list , tuple ))
237242
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 })
240245
241246 self ._body = request_body
242247
@@ -252,8 +257,8 @@ def __init__(self, conn, name, args):
252257 super (RequestEval , self ).__init__ (conn )
253258 assert isinstance (args , (list , tuple ))
254259
255- request_body = msgpack . dumps ({IPROTO_EXPR : name ,
256- IPROTO_TUPLE : args })
260+ request_body = self . _dumps ({IPROTO_EXPR : name ,
261+ IPROTO_TUPLE : args })
257262
258263 self ._body = request_body
259264
@@ -280,10 +285,10 @@ class RequestUpsert(Request):
280285 def __init__ (self , conn , space_no , index_no , tuple_value , op_list ):
281286 super (RequestUpsert , self ).__init__ (conn )
282287
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 })
287292
288293 self ._body = request_body
289294
@@ -297,7 +302,7 @@ class RequestJoin(Request):
297302 # pylint: disable=W0231
298303 def __init__ (self , conn , server_uuid ):
299304 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 })
301306 self ._body = request_body
302307
303308
@@ -312,7 +317,7 @@ def __init__(self, conn, cluster_uuid, server_uuid, vclock):
312317 super (RequestSubscribe , self ).__init__ (conn )
313318 assert isinstance (vclock , dict )
314319
315- request_body = msgpack . dumps ({
320+ request_body = self . _dumps ({
316321 IPROTO_CLUSTER_UUID : cluster_uuid ,
317322 IPROTO_SERVER_UUID : server_uuid ,
318323 IPROTO_VCLOCK : vclock
@@ -329,6 +334,6 @@ class RequestOK(Request):
329334 # pylint: disable=W0231
330335 def __init__ (self , conn , sync ):
331336 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 })
334339 self ._body = request_body
0 commit comments