Exemplo n.º 1
0
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())
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
def reply(builder):
    reply_to = ("example-runner", "reply", "0")
    builder.with_invocation(Hello(), reply_to)
Exemplo n.º 4
0
def state4(builder):
    counter = Counter()
    counter.value = 1
    builder.with_state("counter", counter)
    builder.with_invocation(Hello())
Exemplo n.º 5
0
def state1(builder):
    builder.with_state("counter")
    builder.with_invocation(Hello())
Exemplo n.º 6
0
def union_type_hint(builder):
    hello = Hello()
    builder.with_invocation(hello)

    another_hello = AnotherHello()
    builder.with_invocation(another_hello)
Exemplo n.º 7
0
def hello(builder):
    msg = Hello()
    msg.world = "Hello world!"
    builder.with_invocation(msg)