Home

protoc

Protoc, short for Protocol Buffers compiler, is a key component of Google's Protocol Buffers data interchange format. It reads .proto files that define messages, enums, services, and extensions, and generates source code in target languages to serialize, deserialize, and validate the defined data structures.

Protoc works with language-specific code generators, either built into the protoc distribution or provided as plugins.

Typical usage involves invoking protoc with an input path and language-specific output options. For example, protoc

Protoc is distributed as part of the Protocol Buffers project, available as pre-built binaries or source. It

Supported
languages
include
C++,
Java,
Python,
Go,
C#,
JavaScript,
Ruby,
PHP,
and
Dart,
among
others.
In
addition
to
message
definitions,
protoc
can
generate
gRPC
service
stubs
using
the
corresponding
grpc
plugins
(for
example,
protoc-gen-grpc-java).
It
can
also
emit
descriptor
sets
that
describe
the
entire
schema
for
use
in
reflection-based
tooling.
-I=src
--cpp_out=build/gen
src/person.proto
compiles
to
C++
code;
protoc
--java_out=build/gen
src/person.proto
compiles
to
Java
code.
You
can
generate
code
for
multiple
files
in
a
single
run,
supply
multiple
--proto_path
directories,
and
request
additional
artifacts
such
as
--descriptor_set_out
for
a
FileDescriptorSet.
Plugins
can
be
specified
via
--plugin
to
enable
alternative
code
generators
or
gRPC
stubs.
is
commonly
integrated
into
build
systems
like
Bazel,
CMake,
Gradle,
or
Maven.
Proto
syntax
options
(proto2
vs
proto3)
affect
field
semantics,
with
proto3
simplifying
optional
fields
and
removing
required
fields,
which
influences
generated
code
behavior.