@@ -810,18 +810,19 @@ def deserialize(self, msg_list, content=True, copy=True):
810810 Whether to unpack the content dict (True), or leave it packed
811811 (False).
812812 copy : bool (True)
813- Whether to return the bytes (True), or the non-copying Message
814- object in each place (False).
813+ Whether msg_list contains bytes (True) or the non-copying Message
814+ objects in each place (False).
815815
816816 Returns
817817 -------
818818 msg : dict
819819 The nested message dict with top-level keys [header, parent_header,
820- content, buffers].
820+ content, buffers]. The buffers are returned as memoryviews.
821821 """
822822 minlen = 5
823823 message = {}
824824 if not copy :
825+ # pyzmq didn't copy the first parts of the message, so we'll do it
825826 for i in range (minlen ):
826827 msg_list [i ] = msg_list [i ].bytes
827828 if self .auth is not None :
@@ -846,8 +847,11 @@ def deserialize(self, msg_list, content=True, copy=True):
846847 message ['content' ] = self .unpack (msg_list [4 ])
847848 else :
848849 message ['content' ] = msg_list [4 ]
849-
850- message ['buffers' ] = msg_list [5 :]
850+ buffers = [memoryview (b ) for b in msg_list [5 :]]
851+ if buffers and buffers [0 ].shape is None :
852+ # force copy to workaround pyzmq #646
853+ buffers = [memoryview (b .bytes ) for b in msg_list [5 :]]
854+ message ['buffers' ] = buffers
851855 # adapt to the current version
852856 return adapt (message )
853857
0 commit comments