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