Esempio n. 1
0
def run():
    channel = grpc.insecure_channel('localhost:50051')
    stub = db_pb2_grpc.DbStub(channel)

    to_serialize = test_pb2.KeyInt(int_key=12312)

    serializable = any_pb2.Any()
    serializable.Pack(to_serialize)

    stub.Put(db_pb2.PutReq(serializable=serializable))

    new_put = test_pb2.NonKeyableNested()
    new_put.int_key = 234567
    new_put.nested_nonkeyable_message.boolean = False

    serializable = any_pb2.Any()
    serializable.Pack(new_put)

    stub.Put(db_pb2.PutReq(serializable=serializable))

    key = storage_pb2.Key(message_type="schema.NonKeyableNested",
                          field="int_key",
                          value=b"234567")

    retrieved = stub.Get(db_pb2.GetReq(key=key))

    retrieved_unpacked = test_pb2.NonKeyableNested()

    retrieved.message.Unpack(retrieved_unpacked)

    print(retrieved_unpacked.nested_nonkeyable_message.boolean)
Esempio n. 2
0
def run():
    channel = grpc.insecure_channel('localhost:50051')
    stub = db_pb2_grpc.DbStub(channel)

    # to_serialize = test_pb2.KeyInt(
    #         int_key = 12312
    # )

    # serializable = any_pb2.Any()
    # serializable.Pack(to_serialize)

    # stub.Put(db_pb2.PutReq(
    #     serializable = serializable
    # ))
    message_list = ["first", "second"]

    # for message in message_list:

    new_put = test_pb2.NonKeyableNested()
    new_put.int_key = 36
    new_put.string_key = 'first'
    new_put.nested_nonkeyable_message.boolean = True

    serializable = any_pb2.Any()
    serializable.Pack(new_put)

    stub.Put(db_pb2.PutReq(serializable=serializable))

    key = storage_pb2.Key(message_type="schema.NonKeyableNested",
                          field="int_key",
                          value=b"36")

    retrieved = stub.Get(db_pb2.GetReq(key=key))

    retrieved_unpacked = test_pb2.NonKeyableNested()

    retrieved.message.Unpack(retrieved_unpacked)

    print(retrieved_unpacked.int_key)
Esempio n. 3
0
def run():
    channel = grpc.insecure_channel('localhost:50051')
    stub = db_pb2_grpc.DbStub(channel)

    to_serialize = test_pb2.KeyInt(int_key=12312)

    serializable = any_pb2.Any()
    serializable.Pack(to_serialize)

    stub.Put(db_pb2.PutReq(serializable=serializable))

    key = storage_pb2.Key(message_type="schema.KeyInt",
                          field="int_key",
                          value=b"12312")

    retrieved = stub.Get(db_pb2.GetReq(key=key))

    retrieved_unpacked = test_pb2.KeyInt()

    retrieved.message.Unpack(retrieved_unpacked)

    print(retrieved_unpacked)
Esempio n. 4
0
def run():
    channel = grpc.insecure_channel('localhost:50051')
    stub = db_pb2_grpc.DbStub(channel)

    # to_serialize = test_pb2.KeyInt(
    #         int_key = 12312
    # )

    # serializable = any_pb2.Any()
    # serializable.Pack(to_serialize)

    # stub.Put(db_pb2.PutReq(
    #     serializable = serializable
    # ))
    message_list = ["first", "second"]

    # for message in message_list:

    new_put = test_pb2.RepeatedKeyStr()
    new_put.int_key_repeated.extend(message_list)

    serializable = any_pb2.Any()
    serializable.Pack(new_put)

    stub.Put(db_pb2.PutReq(serializable=serializable))

    key = storage_pb2.Key(message_type="schema.RepeatedKeyStr",
                          field="int_key_repeated",
                          value=b"f")

    retrieved = stub.Get(db_pb2.GetReq(key=key))

    retrieved_unpacked = test_pb2.RepeatedKeyStr()

    retrieved.message.Unpack(retrieved_unpacked)

    print(retrieved_unpacked.int_key_repeated[0])
Esempio n. 5
0
def send_get_request(stub, key, retrieved_unpacked):

    retrieved = stub.Get(db_pb2.GetReq(key=key))
    retrieved.message.Unpack(retrieved_unpacked)
    return