Example #1
0
 def __init__(
     self,
     request: Optional[RequestSourceType] = None,
 ):
     self.buffer = None
     try:
         if isinstance(request, jina_pb2.DataRequestProto):
             self._pb_body = request
         elif isinstance(request, dict):
             self._pb_body = jina_pb2.DataRequestProto()
             json_format.ParseDict(request, self._pb_body)
         elif isinstance(request, str):
             self._pb_body = jina_pb2.DataRequestProto()
             json_format.Parse(request, self._pb_body)
         elif isinstance(request, bytes):
             self.buffer = request
         elif request is not None:
             # note ``None`` is not considered as a bad type
             raise ValueError(f'{typename(request)} is not recognizable')
         else:
             self._pb_body = jina_pb2.DataRequestProto()
             self._pb_body.header.request_id = random_identity()
     except Exception as ex:
         raise BadRequestType(
             f'fail to construct a {self.__class__} object from {request}'
         ) from ex
Example #2
0
    def decompress(self):
        call_counts.put_nowait('called')
        from jina.proto import jina_pb2

        self._pb_body = jina_pb2.DataRequestProto()
        self._pb_body.ParseFromString(self.buffer)
        self.buffer = None
Example #3
0
 def _decompress(self):
     self._pb_body = jina_pb2.DataRequestProto()
     self._pb_body.ParseFromString(self.buffer)
     self.buffer = None
Example #4
0
def req():
    r = jina_pb2.DataRequestProto()
    r.header.request_id = random_identity()
    r.data.docs.docs.add()
    return r