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, --root
specifies 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 name
string Short name as in
google/protobuf/[name].proto
or full file namejson
Object.<string, *> JSON definition within
google.protobuf
if a short name, otherwise the file's root definitionProperties:
Name Type Description google/protobuf/any.proto
INamespace Any
google/protobuf/duration.proto
INamespace Duration
google/protobuf/empty.proto
INamespace Empty
google/protobuf/struct.proto
INamespace Struct, Value, NullValue and ListValue
google/protobuf/timestamp.proto
INamespace Timestamp
google/protobuf/wrappers.proto
INamespace 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 mtype
Type Message type
Returns:
Type Description Codegen Codegen instance -
encoder(mtype){ Codegen }
-
Generates an encoder specific to the specified message type.
Name Type Description mtype
Type 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 filename
string | Array.<string> One or multiple files to load
root
Root Root namespace, defaults to create a new one if omitted.
callback
LoadCallback 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 filename
string | Array.<string> One or multiple files to load
callback
LoadCallback 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 filename
string | Array.<string> One or multiple files to load
root
Root 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 filename
string | Array.<string> One or multiple files to load
root
Root 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 source
string Source contents
root
Root Root to populate
options
IParseOptions optional Parse options. Defaults to parse.defaults when omitted.
Properties:
Name Type Default Description filename
string null Currently processing file name for error reporting, if known
defaults
IParseOptions 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 source
string Source contents
options
IParseOptions optional Parse options. Defaults to parse.defaults when omitted.
Properties:
Name Type Default Description filename
string null Currently processing file name for error reporting, if known
defaults
IParseOptions 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 source
string Source contents
Returns:
Type Description ITokenizerHandle Tokenizer handle -
verifier(mtype){ Codegen }
-
Generates a verifier specific to the specified message type.
Name Type Description mtype
Type 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 error
Error | 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 formatStringOrScope
string | 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 error
Error nullable Error, if any, otherwise
null
contents
string 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 prototype
Object Target prototype
fieldName
string Field name
Returns:
Type Description undefined -
LoadCallback(error, root){ undefined }
-
Name Type Description error
Error | null Error, if any, otherwise
null
root
Root 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 prototype
Object Target prototype
oneofName
string 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 value
string | undefined Field name
Returns:
Type Description undefined -
PoolAllocator(size){ Uint8Array }
-
An allocator as used by util.pool.
Name Type Description size
number Buffer size
Returns:
Type Description Uint8Array Buffer -
PoolSlicer(start, end){ Uint8Array }
-
A slicer as used by util.pool.
This:
- {Uint8Array}
Name Type Description start
number Start offset
end
number 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 method
Method | rpc.ServiceMethod.<Message.<{}>, Message.<{}>> Reflected or static method being called
requestData
Uint8Array Request data
callback
RPCImplCallback 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 error
Error | null Error, if any, otherwise
null
response
Uint8Array | null optional Response data or
null
to 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 line
number optional Line number
Returns:
Type Description string | null Comment text or null
if none -
TokenizerHandleNext(){ string | null }
-
Gets the next token and advances.
Returns:
Type Description string | null Next token or null
on eof -
TokenizerHandlePeek(){ string | null }
-
Peeks for the next token.
Returns:
Type Description string | null Next token or null
on eof -
TokenizerHandlePush(token){ undefined }
-
Pushes a token back to the stack.
Name Type Description token
string Token
Returns:
Type Description undefined -
TokenizerHandleSkip(expected, optional){ boolean }
-
Skips the next token.
Name Type Default Description expected
string Expected token
optional
boolean 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 target
Constructor.<T> Target constructor
Returns:
Type Description undefined -
WrapperFromObjectConverter(object){ Message.<{}> }
-
From object converter part of an IWrapper.
This:
Name Type Description object
Object.<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 message
Message.<{}> Message instance
options
IConversionOptions optional Conversion options
Returns:
Type Description Object.<string, *> Plain object