js_generator.h
#include <google/protobuf/compiler/js/js_generator.h>
namespace google::protobuf::compiler::js
Generates JavaScript code for a given .proto file.
Classes in this file | |
---|---|
CodeGenerator implementation which generates a JavaScript source file and header. |
struct GeneratorOptions
#include <google/protobuf/compiler/js/js_generator.h>
namespace google::protobuf::compiler::js
Members | |
---|---|
enum | ImportStyle What style of imports should be used. more... |
enum | OutputMode |
std::string | output_dir Output path. |
std::string | namespace_prefix Namespace prefix. |
bool | binary Enable binary-format support? |
enum google::protobuf::compiler::js::GeneratorOptions::ImportStyle | import_style |
bool | add_require_for_enums Add a goog.requires() call for each enum type used. more... |
bool | testonly Set this as a test-only module via goog.setTestOnly(); . |
std::string | library Create a library with name <name>_lib.js rather than a separate .js file per type? |
bool | error_on_name_conflict Error if there are two types that would generate the same output file? |
std::string | extension The extension to use for output file names. |
bool | one_output_file_per_input_file Create a separate output file for each input file? |
bool | annotate_code If true, we should append annotations as comments on the last line for generated .js file. more... |
| GeneratorOptions() |
bool | ParseFromOptions(const std::vector< std::pair< std::string, std::string > > & options, std::string * error) |
std::string | GetFileNameExtension() const Returns the file name extension to use for generated code. |
OutputMode | output_mode() const Indicates how to output the generated code based on the provided options. |
enum GeneratorOptions::ImportStyle {
kImportClosure,
kImportCommonJs,
kImportCommonJsStrict,
kImportBrowser,
kImportEs6
}
kImportClosure,
kImportCommonJs,
kImportCommonJsStrict,
kImportBrowser,
kImportEs6
}
What style of imports should be used.
kImportClosure | goog.require() |
kImportCommonJs | require() |
kImportCommonJsStrict | require() with no global export |
kImportBrowser | no import statements |
kImportEs6 | import { member } from '' |
enum GeneratorOptions::OutputMode {
kOneOutputFilePerInputFile,
kOneOutputFilePerSCC,
kEverythingInOneFile
}
kOneOutputFilePerInputFile,
kOneOutputFilePerSCC,
kEverythingInOneFile
}
kOneOutputFilePerInputFile | Create an output file for each input .proto file. |
kOneOutputFilePerSCC | Create an output file for each type. |
kEverythingInOneFile | Put everything in a single file named by the library option. |
bool GeneratorOptions::add_require_for_enums
Add a goog.requires()
call for each enum type used.
If not set, a forward declaration with goog.forwardDeclare
is produced instead.
bool GeneratorOptions::annotate_code
If true, we should append annotations as comments on the last line for generated .js file.
Annotations used by tools like to provide cross-references between .js and .proto files. Annotations are encoded as base64 proto of GeneratedCodeInfo message (see descriptor.proto).
class Generator: public CodeGenerator
#include <google/protobuf/compiler/js/js_generator.h>
namespace google::protobuf::compiler::js
CodeGenerator implementation which generates a JavaScript source file and header.
If you create your own protocol compiler binary and you want it to support JavaScript output, you can do so by registering an instance of this CodeGenerator with the CommandLineInterface in your main() function.
Members | |
---|---|
| Generator() |
virtual | ~Generator() |
virtual bool | Generate(const FileDescriptor * file, const std::string & parameter, GeneratorContext * generator_context, std::string * error) const Generates code for the given proto file, generating one or more files in the given output directory. more... |
virtual bool | HasGenerateAll() const This is no longer used, but this class is part of the opensource protobuf library, so it has to remain to keep vtables the same for the current version of the library. more... |
virtual bool | GenerateAll(const std::vector< const FileDescriptor * > & files, const std::string & parameter, GeneratorContext * generator_context, std::string * error) const Generates code for all given proto files. more... |
virtual uint64 | GetSupportedFeatures() const Implement this to indicate what features this code generator supports. more... |
virtual bool Generator::Generate(
const FileDescriptor * file,
const std::string & parameter,
GeneratorContext * generator_context,
std::string * error) const
const FileDescriptor * file,
const std::string & parameter,
GeneratorContext * generator_context,
std::string * error) const
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 to pass generator specific parameters. It is empty if no parameter was given. ParseGeneratorParameter (below), can be used to accept multiple parameters within the single parameter command line flag.
Returns true if successful. Otherwise, sets *error to a description of the problem (e.g. "invalid parameter") and returns false.
virtual bool Generator::HasGenerateAll() const
This is no longer used, but this class is part of the opensource protobuf library, so it has to remain to keep vtables the same for the current version of the library.
When protobufs does a api breaking change, the method can be removed.
virtual bool Generator::GenerateAll(
const std::vector< const FileDescriptor * > & files,
const std::string & parameter,
GeneratorContext * generator_context,
std::string * error) const
const std::vector< const FileDescriptor * > & files,
const std::string & parameter,
GeneratorContext * generator_context,
std::string * error) const
Generates code for all given proto files.
WARNING: The canonical code generator design produces one or two output files per input .proto file, and we do not wish to encourage alternate designs.
A parameter is given as passed on the command line, as in |Generate()| above.
Returns true if successful. Otherwise, sets *error to a description of the problem (e.g. "invalid parameter") and returns false.
virtual uint64 Generator::GetSupportedFeatures() const
Implement this to indicate what features this code generator supports.
This should be a bitwise OR of features from the Features enum in plugin.proto.