Global

Top Level

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 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

common(name, json){ undefined }

Provides common type definitions.
Can also be used to provide additional google types or your own custom types.

Parameters:
name string

Short name as in google/protobuf/[name].proto or full file name

json Object.<string, *>

JSON definition within google.protobuf if a short name, otherwise the file's root definition

Properties:
google/protobuf/any.proto INamespace

Any

google/protobuf/duration.proto INamespace

Duration

google/protobuf/empty.proto INamespace

Empty

google/protobuf/field_mask.proto INamespace

FieldMask

google/protobuf/struct.proto INamespace

Struct, Value, NullValue and ListValue

google/protobuf/timestamp.proto INamespace

Timestamp

google/protobuf/wrappers.proto INamespace

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:
mtype Type

Message type

Returns:
Codegen Codegen instance

encoder(mtype){ Codegen }

Generates an encoder specific to the specified message type.

Parameters:
mtype Type

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:
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:
undefined

load(filename, callback){ undefined }

Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.

Parameters:
filename string | Array.<string>

One or multiple files to load

callback LoadCallback

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:
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:
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:
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:
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:
source string

Source contents

root Root

Root to populate

options IParseOptions optional

Parse options. Defaults to parse.defaults when omitted.

Properties:
filename string null

Currently processing file name for error reporting, if known

defaults IParseOptions

Default IParseOptions

Returns:
IParserResult Parser result

parse(source, options){ IParserResult }

Parses the given .proto source and returns an object with the parsed contents.

Parameters:
source string

Source contents

options IParseOptions optional

Parse options. Defaults to parse.defaults when omitted.

Properties:
filename string null

Currently processing file name for error reporting, if known

defaults IParseOptions

Default IParseOptions

Returns:
IParserResult Parser result

tokenize(source, alternateCommentMode){ ITokenizerHandle }

Tokenizes the given .proto source and returns an object with useful utility functions.

Parameters:
source string

Source contents

alternateCommentMode boolean

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:
mtype Type

Message type

Returns:
Codegen Codegen instance

Type Definitions

Any extension field descriptor.

Any nested object descriptor.

Codegen(formatStringOrScope, formatParams){ Codegen | function }

Appends code to the function's body or finishes generation.

Parameters:
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:
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:
error Error nullable

Error, if any, otherwise null

contents string optional

File contents, if there hasn't been an error

Returns:
undefined

FieldDecorator(prototype, fieldName){ undefined }

Decorator function as returned by Field.d and MapField.d (TypeScript).

Parameters:
prototype Object

Target prototype

fieldName string

Field name

Deprecated:
Legacy TypeScript decorator support. Will be removed in a future release.
Returns:
undefined

LoadCallback(error, root){ undefined }

A node-style callback as used by load and Root#load.

Parameters:
error Error | null

Error, if any, otherwise null

root Root optional

Root, if there hasn't been an error

Returns:
undefined

OneOfDecorator(prototype, oneofName){ undefined }

Decorator function as returned by OneOf.d (TypeScript).

Parameters:
prototype Object

Target prototype

oneofName string

OneOf name

Deprecated:
Legacy TypeScript decorator support. Will be removed in a future release.
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:
value string | undefined

Field name

Returns:
undefined

PoolAllocator(size){ Uint8Array }

An allocator as used by util.pool.

Parameters:
size number

Buffer size

Returns:
Uint8Array Buffer

PoolSlicer(start, end){ Uint8Array }

A slicer as used by util.pool.

This:
  • Uint8Array
Parameters:
start number

Start offset

end number

End offset

Returns:
Uint8Array Buffer slice

Properties { { [P in keyof T]?: T[P] } }

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.

Parameters:
method Method | rpc.ServiceMethod.<Message.<{}>, Message.<{}>>

Reflected or static method being called

requestData Uint8Array

Request data

callback RPCImplCallback

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);
    });
}

RPCImplCallback(error, response){ undefined }

Node-style callback as used by RPCImpl.

Parameters:
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 error

Returns:
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:
line number optional

Line number

Returns:
string | null Comment text or null if none

TokenizerHandleNext(){ string | null }

Gets the next token and advances.

Returns:
string | null Next token or null on eof

TokenizerHandlePeek(){ string | null }

Peeks for the next token.

Returns:
string | null Next token or null on eof

TokenizerHandlePush(token){ undefined }

Pushes a token back to the stack.

Parameters:
token string

Token

Returns:
undefined

TokenizerHandleSkip(expected, optional){ boolean }

Skips the next token.

Parameters:
expected string

Expected token

optional boolean false optional

If optional

Throws:
Error

If the token didn't match and is not optional

Returns:
boolean Whether the token matched

TypeDecorator(target){ undefined }

Decorator function as returned by Type.d (TypeScript).

Parameters:
target Constructor.<T>

Target constructor

Deprecated:
Legacy TypeScript decorator support. Will be removed in a future release.
Returns:
undefined

WrapperFromObjectConverter(object){ Message.<{}> }

From object converter part of an IWrapper.

This:
Parameters:
object Object.<string, *>

Plain object

Returns:
Message.<{}> Message instance

WrapperToObjectConverter(message, options){ Object<string, *> }

To object converter part of an IWrapper.

This:
Parameters:
message Message.<{}>

Message instance

options IConversionOptions optional

Conversion options

Returns:
Object.<string, *> Plain object

asPromiseCallback(error, params){ undefined }

Callback as used by util.asPromise.

Parameters:
error Error | null

Error, if any

params * repeatable

Additional arguments

Returns:
undefined