Protocol Buffers

code_generator.h

#include <google/protobuf/compiler/code_generator.h>
namespace google::protobuf::compiler

Defines the abstract interface implemented by each of the language-specific code generators.

Classes in this file

The abstract interface to a class which generates code implementing a particular proto file in a particular language.
CodeGenerators generate one or more files in a given directory.

File Members

These definitions are not part of any class.
typedef
GeneratorContext OutputDirectory
The type GeneratorContext was once called OutputDirectory. more...
void
ParseGeneratorParameter(const string & , vector< pair< string, string > > * )
Several code generators treat the parameter argument as holding a list of options separated by commas. more...

typedef compiler::OutputDirectory

The type GeneratorContext was once called OutputDirectory.

This typedef provides backward compatibility.


void compiler::ParseGeneratorParameter(
        const string & ,
        vector< pair< string, string > > * )

Several code generators treat the parameter argument as holding a list of options separated by commas.

This helper function parses a set of comma-delimited name/value pairs: e.g., "foo=bar,baz,qux=corge" parses to the pairs:

("foo", "bar"), ("baz", ""), ("qux", "corge")

class CodeGenerator

#include <google/protobuf/compiler/code_generator.h>
namespace google::protobuf::compiler

The abstract interface to a class which generates code implementing a particular proto file in a particular language.

A number of these may be registered with CommandLineInterface to support various languages.

Known subclasses:

Members

CodeGenerator()
virtual
~CodeGenerator()
virtual bool
Generate(const FileDescriptor * file, const string & parameter, GeneratorContext * generator_context, string * error) const = 0
Generates code for the given proto file, generating one or more files in the given output directory. more...

virtual bool CodeGenerator::Generate(
        const FileDescriptor * file,
        const string & parameter,
        GeneratorContext * generator_context,
        string * error) const = 0

Generates code for the given proto file, generating one or more files in the given output directory.

A parameter to be passed to the generator can be specified on the command line. This is intended to be used by Java and similar languages to specify which specific class from the proto file is to be generated, though it could have other uses as well. It is empty if no parameter was given.

Returns true if successful. Otherwise, sets *error to a description of the problem (e.g. "invalid parameter") and returns false.

class GeneratorContext

#include <google/protobuf/compiler/code_generator.h>
namespace google::protobuf::compiler

CodeGenerators generate one or more files in a given directory.

This abstract interface represents the directory to which the CodeGenerator is to write and other information about the context in which the Generator runs.

Members

GeneratorContext()
virtual
~GeneratorContext()
virtual io::ZeroCopyOutputStream *
Open(const string & filename) = 0
Opens the given file, truncating it if it exists, and returns a ZeroCopyOutputStream that writes to the file. more...
virtual io::ZeroCopyOutputStream *
OpenForInsert(const string & filename, const string & insertion_point)
Creates a ZeroCopyOutputStream which will insert code into the given file at the given insertion point. more...
virtual void
ListParsedFiles(vector< const FileDescriptor * > * output)
Returns a vector of FileDescriptors for all the files being compiled in this run. more...

virtual io::ZeroCopyOutputStream *
    GeneratorContext::Open(
        const string & filename) = 0

Opens the given file, truncating it if it exists, and returns a ZeroCopyOutputStream that writes to the file.

The caller takes ownership of the returned object. This method never fails (a dummy stream will be returned instead).

The filename given should be relative to the root of the source tree. E.g. the C++ generator, when generating code for "foo/bar.proto", will generate the files "foo/bar.pb.h" and "foo/bar.pb.cc"; note that "foo/" is included in these filenames. The filename is not allowed to contain "." or ".." components.


virtual io::ZeroCopyOutputStream *
    GeneratorContext::OpenForInsert(
        const string & filename,
        const string & insertion_point)

Creates a ZeroCopyOutputStream which will insert code into the given file at the given insertion point.

See plugin.proto (plugin.pb.h) for more information on insertion points. The default implementation assert-fails -- it exists only for backwards-compatibility.

WARNING: This feature is currently EXPERIMENTAL and is subject to change.


virtual void GeneratorContext::ListParsedFiles(
        vector< const FileDescriptor * > * output)

Returns a vector of FileDescriptors for all the files being compiled in this run.

Useful for languages, such as Go, that treat files differently when compiled as a set rather than individually.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.