Book Image

Practical gRPC

By : Joshua B. Humphries, David Konsumer, David Muto, Robert Ross, Carles Sistare
Book Image

Practical gRPC

By: Joshua B. Humphries, David Konsumer, David Muto, Robert Ross, Carles Sistare

Overview of this book

While building systems that contain several components, you need a framework that is fast and has minimal network overhead. gRPC is one such open-source tool that is quickly becoming popular and gaining popularity with programmers. Practical gRPC introduces you to gRPC and explains how it compares and contrasts with similar technologies. You’ll be introduced to key technologies such as Protocol Buffers, and work your way up from basic gRPC usage, all the way through to its more advanced capabilities. You’ll learn the best practices for defining and evolving your gRPC APIs, and discover how different tools can be leveraged to get the most out of gRPC and even extend it. By the end of this book, you'll have all the information you need to get started building systems with gRPC.
Table of Contents (13 chapters)
11
11. Extending gRPC services

Enums

Enums help you to spare a lot of bytes in serialized messages, specially when the strings sent through the network are repetitive, such us status codes, error messages, etc. The serialized value will contain only the tag of the field instead of the whole value.

syntax = "proto2";

message Film {
    enum ProducerCompanies {
        UNKNOWN = 0;
        WARNER_BROS = 1;
        PARAMOUNT = 2;
        NETFLIX = 3;
    }
    ProducerCompanies Producer = 1 [default = UNKNOWN];
}

Notice that the UNKNOWN enum type is highly recommended when the Producer set up in the code doesn’t exist in the list. When it doesn’t exist, it is automatically set to 0, to avoid future inconsistencies.