コード例 #1
0
def round_trip(typename, fn, to: InvocationBuilder) -> dict:
    functions = StatefulFunctions()
    functions.register(typename, fn)
    handler = RequestReplyHandler(functions)
    f = FromFunction()
    f.ParseFromString(handler(to.SerializeToString()))
    return MessageToDict(f, preserving_proto_field_name=True)
コード例 #2
0
def round_trip(functions: StatefulFunctions, to: InvocationBuilder) -> dict:
    handler = RequestReplyHandler(functions)

    in_bytes = to.SerializeToString()
    out_bytes = handler.handle_sync(in_bytes)

    f = FromFunction()
    f.ParseFromString(out_bytes)
    return MessageToDict(f, preserving_proto_field_name=True)
コード例 #3
0
 def invoke(self, typename):
     fn = self.examples[typename]
     builder = InvocationBuilder()
     type, name = typename.split("/")
     builder.with_target(type, name, "some id")
     fn(builder)
     result = post(builder.SerializeToString())
     from_fn = FromFunction()
     from_fn.ParseFromString(result.content)
     pprint.pprint(MessageToDict(from_fn, preserving_proto_field_name=True, including_default_value_fields=True))
コード例 #4
0
def async_round_trip(functions: StatefulFunctions, to: InvocationBuilder) -> dict:
    handler = AsyncRequestReplyHandler(functions)

    in_bytes = to.SerializeToString()
    future = handler(in_bytes)
    out_bytes = asyncio.get_event_loop().run_until_complete(future)

    f = FromFunction()
    f.ParseFromString(out_bytes)
    return MessageToDict(f, preserving_proto_field_name=True)
コード例 #5
0
 def _parse_result_bytes(result_bytes):
     f = FromFunction()
     f.ParseFromString(result_bytes)
     return f