Reader small image

You're reading from  Protocol Buffers Handbook

Product typeBook
Published inApr 2024
PublisherPackt
ISBN-139781805124672
Edition1st Edition
Right arrow
Author (1)
Clément Jean
Clément Jean
author image
Clément Jean

Clément Jean is the CTO of Education for Ethiopia, a start-up focusing on educating K-12 students in Ethiopia. On top of that, he is also an online instructor (on Udemy, Linux Foundation, and others) teaching people about diff erent kinds of technologies. In both his occupations, he deals with technologies such as Protobuf and gRPC and how to apply them to real-life use cases. His overall goal is to empower people through education and technology.
Read more about Clément Jean

Right arrow

Listing entries

Let us now focus on listing all the entries that are stored in the addressbook.db file. We will first start with the business logic and we will then go to the CLI part of the application.

The business logic

The job left for the CLI to be completed is rather small. We only need to read data from the database and display it on the standard output. Let us start by reading the data from the database:

def list_contacts(db: IO[bytes]):
  book = read_from_db(db)
  #...

Next, we can order the list of contacts alphabetically. This was mostly done for testing purposes, but it could be used for more advanced features such as filtering or paging. Here, we will simply focus on displaying all the contacts. The sorting looks like the following:

def list_contacts(db: IO[bytes]):
  book = read_from_db(db)
  for name in sorted(book.contacts.keys()):
    #...

Now that we have sorted names, we can just display...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Protocol Buffers Handbook
Published in: Apr 2024Publisher: PacktISBN-13: 9781805124672

Author (1)

author image
Clément Jean

Clément Jean is the CTO of Education for Ethiopia, a start-up focusing on educating K-12 students in Ethiopia. On top of that, he is also an online instructor (on Udemy, Linux Foundation, and others) teaching people about diff erent kinds of technologies. In both his occupations, he deals with technologies such as Protobuf and gRPC and how to apply them to real-life use cases. His overall goal is to empower people through education and technology.
Read more about Clément Jean