Members
-
build constant{ string }
-
Build type, one of
"full","light"or"minimal". -
roots { Object<string, Root> }
-
Named roots.
This is where pbjs stores generated structures (the option-r, --rootspecifies a name).
Can also be used manually to make roots available accross modules.Example
// pbjs -r myroot -o compiled.js ... // in another module: require("./compiled.js"); // in any subsequent module: var root = protobuf.roots["myroot"]; -
wrappers constant{ Object<string, IWrapper> }
-
Wrappers for common types.
Methods
-
common(name, json){ undefined }
-
Provides common type definitions.
Can also be used to provide additional google types or your own custom types.Name Type Description namestring Short name as in
google/protobuf/[name].protoor full file namejsonObject.<string, *> JSON definition within
google.protobufif a short name, otherwise the file's root definitionProperties:
Name Type Description google/protobuf/any.protoINamespace Any
google/protobuf/duration.protoINamespace Duration
google/protobuf/empty.protoINamespace Empty
google/protobuf/struct.protoINamespace Struct, Value, NullValue and ListValue
google/protobuf/timestamp.protoINamespace Timestamp
google/protobuf/wrappers.protoINamespace Wrappers
Returns:
Type Description undefined Example
// manually provides descriptor.proto (assumes google/protobuf/ namespace and .proto extension) protobuf.common("descriptor", descriptorJson); // manually provides a custom definition (uses my.foo namespace) protobuf.common("my/foo/bar.proto", myFooBarJson); -
configure(){ undefined }
-
Reconfigures the library according to the environment.
Returns:
Type Description undefined -
decoder(mtype){ Codegen }
-
Generates a decoder specific to the specified message type.
Name Type Description mtypeType Message type
Returns:
Type Description Codegen Codegen instance -
encoder(mtype){ Codegen }
-
Generates an encoder specific to the specified message type.
Name Type Description mtypeType Message type
Returns:
Type Description Codegen Codegen instance -
load(filename, root, callback){ undefined }
-
Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
Name Type Description filenamestring | Array.<string> One or multiple files to load
rootRoot Root namespace, defaults to create a new one if omitted.
callbackLoadCallback Callback function
- See:
Returns:
Type Description undefined -
load(filename, callback){ undefined }
-
Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
Name Type Description filenamestring | Array.<string> One or multiple files to load
callbackLoadCallback Callback function
- See:
Returns:
Type Description undefined -
load(filename, root){ Promise<Root> }
-
Loads one or multiple .proto or preprocessed .json files into a common root namespace and returns a promise.
Name Type Description filenamestring | Array.<string> One or multiple files to load
rootRoot optional Root namespace, defaults to create a new one if omitted.
- See:
Returns:
Type Description Promise.<Root> Promise -
loadSync(filename, root){ Root }
-
Synchronously loads one or multiple .proto or preprocessed .json files into a common root namespace (node only).
Name Type Description filenamestring | Array.<string> One or multiple files to load
rootRoot optional Root namespace, defaults to create a new one if omitted.
- See:
Throws:
Type Description Error If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
Returns:
Type Description Root Root namespace -
parse(source, root, options){ IParserResult }
-
Parses the given .proto source and returns an object with the parsed contents.
Name Type Description sourcestring Source contents
rootRoot Root to populate
optionsIParseOptions optional Parse options. Defaults to parse.defaults when omitted.
Properties:
Name Type Default Description filenamestring null Currently processing file name for error reporting, if known
defaultsIParseOptions Default IParseOptions
Returns:
Type Description IParserResult Parser result -
parse(source, options){ IParserResult }
-
Parses the given .proto source and returns an object with the parsed contents.
Name Type Description sourcestring Source contents
optionsIParseOptions optional Parse options. Defaults to parse.defaults when omitted.
Properties:
Name Type Default Description filenamestring null Currently processing file name for error reporting, if known
defaultsIParseOptions Default IParseOptions
Returns:
Type Description IParserResult Parser result -
tokenize(source){ ITokenizerHandle }
-
Tokenizes the given .proto source and returns an object with useful utility functions.
Name Type Description sourcestring Source contents
Returns:
Type Description ITokenizerHandle Tokenizer handle -
verifier(mtype){ Codegen }
-
Generates a verifier specific to the specified message type.
Name Type Description mtypeType Message type
Returns:
Type Description Codegen Codegen instance
Type Definitions
-
AnyExtensionField { IExtensionField | IExtensionMapField }
-
Any extension field descriptor.
-
AnyNestedObject { IEnum | IType | IService | AnyExtensionField | INamespace }
-
Any nested object descriptor.
-
asPromiseCallback(error, params){ undefined }
-
Callback as used by util.asPromise.
Name Type Description errorError | null Error, if any
params* repeatable Additional arguments
Returns:
Type Description undefined -
Codegen(formatStringOrScope, formatParams){ Codegen | function }
-
Appends code to the function's body or finishes generation.
Name Type Description formatStringOrScopestring | Object.<string, *> optional Format string or, to finish the function, an object of additional scope variables, if any
formatParams* optional repeatable Format parameters
Throws:
Type Description Error If format parameter counts do not match
Returns:
Type Description Codegen | function Itself or the generated function if finished -
EventEmitterListener(args){ undefined }
-
Event listener as used by util.EventEmitter.
Name Type Description args* repeatable Arguments
Returns:
Type Description undefined -
FetchCallback(error, contents){ undefined }
-
Node-style callback as used by util.fetch.
Name Type Description errorError nullable Error, if any, otherwise
nullcontentsstring optional File contents, if there hasn't been an error
Returns:
Type Description undefined -
FieldDecorator(prototype, fieldName){ undefined }
-
Decorator function as returned by Field.d and MapField.d (TypeScript).
Name Type Description prototypeObject Target prototype
fieldNamestring Field name
Returns:
Type Description undefined -
LoadCallback(error, root){ undefined }
-
Name Type Description errorError | null Error, if any, otherwise
nullrootRoot optional Root, if there hasn't been an error
Returns:
Type Description undefined -
OneOfDecorator(prototype, oneofName){ undefined }
-
Decorator function as returned by OneOf.d (TypeScript).
Name Type Description prototypeObject Target prototype
oneofNamestring OneOf name
Returns:
Type Description undefined -
OneOfGetter(){ string | undefined }
-
A OneOf getter as returned by util.oneOfGetter.
Returns:
Type Description string | undefined Set field name, if any -
OneOfSetter(value){ undefined }
-
A OneOf setter as returned by util.oneOfSetter.
Name Type Description valuestring | undefined Field name
Returns:
Type Description undefined -
PoolAllocator(size){ Uint8Array }
-
An allocator as used by util.pool.
Name Type Description sizenumber Buffer size
Returns:
Type Description Uint8Array Buffer -
PoolSlicer(start, end){ Uint8Array }
-
A slicer as used by util.pool.
This:
- {Uint8Array}
Name Type Description startnumber Start offset
endnumber End offset
Returns:
Type Description Uint8Array Buffer slice -
Properties { Object<string, *> }
-
Properties type.
-
RPCImpl(method, requestData, callback){ undefined }
-
RPC implementation passed to Service#create performing a service request on network level, i.e. by utilizing http requests or websockets.
Name Type Description methodMethod | rpc.ServiceMethod.<Message.<{}>, Message.<{}>> Reflected or static method being called
requestDataUint8Array Request data
callbackRPCImplCallback Callback function
Returns:
Type Description undefined Example
function rpcImpl(method, requestData, callback) { if (protobuf.util.lcFirst(method.name) !== "myMethod") // compatible with static code throw Error("no such method"); asynchronouslyObtainAResponse(requestData, function(err, responseData) { callback(err, responseData); }); } -
RPCImplCallback(error, response){ undefined }
-
Node-style callback as used by RPCImpl.
Name Type Description errorError | null Error, if any, otherwise
nullresponseUint8Array | null optional Response data or
nullto signal end of stream, if there hasn't been an errorReturns:
Type Description undefined -
TokenizerHandleCmnt(line){ string | null }
-
Gets the comment on the previous line or, alternatively, the line comment on the specified line.
Name Type Description linenumber optional Line number
Returns:
Type Description string | null Comment text or nullif none -
TokenizerHandleNext(){ string | null }
-
Gets the next token and advances.
Returns:
Type Description string | null Next token or nullon eof -
TokenizerHandlePeek(){ string | null }
-
Peeks for the next token.
Returns:
Type Description string | null Next token or nullon eof -
TokenizerHandlePush(token){ undefined }
-
Pushes a token back to the stack.
Name Type Description tokenstring Token
Returns:
Type Description undefined -
TokenizerHandleSkip(expected, optional){ boolean }
-
Skips the next token.
Name Type Default Description expectedstring Expected token
optionalboolean false optional If optional
Throws:
Type Description Error If the token didn't match and is not optional
Returns:
Type Description boolean Whether the token matched -
TypeDecorator(target){ undefined }
-
Decorator function as returned by Type.d (TypeScript).
Name Type Description targetConstructor.<T> Target constructor
Returns:
Type Description undefined -
WrapperFromObjectConverter(object){ Message.<{}> }
-
From object converter part of an IWrapper.
This:
Name Type Description objectObject.<string, *> Plain object
Returns:
Type Description Message.<{}> Message instance -
WrapperToObjectConverter(message, options){ Object<string, *> }
-
To object converter part of an IWrapper.
This:
Name Type Description messageMessage.<{}> Message instance
optionsIConversionOptions optional Conversion options
Returns:
Type Description Object.<string, *> Plain object