def send(context, message): # context allows you to send messages to other functions, as long as you # know their address. An address is composed of a function type and an id. any = Any() any.Pack(Hello()) context.send("walkthrough/reply", "some-id", any) # see reply() below. # you can also use the convenience alternative, that would pack the argument to a google.protobuf.Any context.pack_and_send("walkthrough/reply", "some-id", Hello())
def any_example(context, any_message): # messages sent to a Python function are always packed into a google.protobuf.Any # (https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/Any.html) # Therefore the first thing we need to do is to unpack it. if not any_message.Is(Hello.DESCRIPTOR): raise TypeError('Unexpected message type') hello = Hello() any_message.Unpack(hello) print(hello)
def reply(builder): reply_to = ("example-runner", "reply", "0") builder.with_invocation(Hello(), reply_to)
def state4(builder): counter = Counter() counter.value = 1 builder.with_state("counter", counter) builder.with_invocation(Hello())
def state1(builder): builder.with_state("counter") builder.with_invocation(Hello())
def union_type_hint(builder): hello = Hello() builder.with_invocation(hello) another_hello = AnotherHello() builder.with_invocation(another_hello)
def hello(builder): msg = Hello() msg.world = "Hello world!" builder.with_invocation(msg)