liveBook · Manning

Protoc

As explained in Go in Practice, Second Edition

protoc is the Protocol Buffer compiler that parses .proto definitions and generates source code for supported languages.

protoc is the Protocol Buffer compiler used with gRPC. It processes a .proto contract and generates language-specific code, reducing serialization and service-integration boilerplate while preserving strong typing across languages. section 11.5

Listing 11.14 A basic proto3 file for a chat server
syntax = "proto3";   #1
package chat;   #2

import "google/protobuf/timestamp.proto";   #3

option go_package = "./ch11";   #4
message CommentRequest {                   #5
    string username = 1;
    string text = 2;
    google.protobuf.Timestamp sent = 3;
}

message CommentResponse {                 
    int32 commentLength = 1;
    int32 previousCommentCount = 2;
}

service ChatService {                                    #6
  rpc RouteComments(Comment) returns (CommentMeta) {}    #6
}

A proto3 definition declares the package, imports shared types, selects a Go output package, defines messages, and declares a gRPC service. section 11.5

protoc - --go_out=. --go-grpc-out=._protos/chat.proto

Run protoc with Go and gRPC output plugins to generate the client and service scaffolding from a .proto file. section 11.5

How Go in Practice, Second Edition covers it

How deep it goes
Explains the compiler’s role, proto3 inputs, and generation command without descending into compiler internals.
Examples
Uses a chat-service proto3 definition and a protoc command generating Go and gRPC output.
What it assumes
Assumes a .proto contract and familiarity with gRPC services, messages, and supported language output.
What you can do after
Operate/configure protoc to generate Go clients and service scaffolding from a proto3 contract.
How it connects
Connects Protocol Buffers with gRPC, RPC, serialization, code generation, and REST trade-offs.

Also explained in

Compare how 4 books explain protoc →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Practice, Second Edition. The section links point to the parts of the book it draws on.