Esempio n. 1
0
def handle_proto_client(connection):

    message = connection.recv()

    addresses = addressBook_pb2.AddressBook()
    addresses.ParseFromString(message)

    print(addresses)

    return (len(message))
Esempio n. 2
0
def handle_proto_client(connection, address):

    data = connection.recv(4)
    print(len(data))
    message_length, = struct.unpack('>I', data)

    #print(message_length)

    message = connection.recv(message_length)

    addresses = addressBook_pb2.AddressBook()
    addresses.ParseFromString(message)

    print(addresses)
    return (len(message))
def create_proto_message(numberOfPeople):

    address_book = addressBook_pb2.AddressBook()

    for x in range(0, int(numberOfPeople)):

        person = address_book.people.add()
        person.id = x
        person.name = "Rosa Luxemburg"
        person.email = "*****@*****.**"
        phone = person.phones.add()
        phone.number = "0178525048"

    message = address_book.SerializeToString()

    return (message)
def send_proto_message(connection, numberOfPeople, i):

    address_book = addressBook_pb2.AddressBook()

    for x in range(1, int(numberOfPeople) + 1):

        person = address_book.people.add()
        person.id = x
        person.name = "Rosa Luxemburg"
        person.email = "*****@*****.**"
        phone = person.phones.add()
        phone.number = "0178525048"

    message = address_book.SerializeToString()

    connection.send(message)
    print("Length of send Proto data: " + str(len(message)))
    print("Type of Proto data send: " + str(type(message)))
    print("Iter: " + str(i))

    return (len(message))
Esempio n. 5
0
import addressBook_pb2

address_book = addressBook_pb2.AddressBook()

f = open("schema/addressbook_proto.bin", "rb")
address_book.ParseFromString(f.read())
f.close()

print(address_book)