protobufjs

  • Version 7.4.0
  • Published
  • 2.77 MB
  • 12 dependencies
  • BSD-3-Clause license

Install

npm i protobufjs
yarn add protobufjs
pnpm add protobufjs

Overview

Protocol Buffers for JavaScript (& TypeScript).

Index

Variables

Functions

Classes

Interfaces

Type Aliases

Namespaces

Variables

variable build

const build: string;
  • Build type, one of "full", "light" or "minimal".

variable roots

let roots: { [k: 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.

variable wrappers

const wrappers: { [k: string]: IWrapper };
  • Wrappers for common types.

Functions

function common

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

    Parameter name

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

    Parameter json

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

function configure

configure: () => void;
  • Reconfigures the library according to the environment.

function decoder

decoder: (mtype: Type) => Codegen;
  • Generates a decoder specific to the specified message type.

    Parameter mtype

    Message type

    Returns

    Codegen instance

function encoder

encoder: (mtype: Type) => Codegen;
  • Generates an encoder specific to the specified message type.

    Parameter mtype

    Message type

    Returns

    Codegen instance

function load

load: {
(filename: string | string[], root: Root, callback: LoadCallback): void;
(filename: string | string[], callback: LoadCallback): void;
(filename: string | string[], root?: Root): Promise<Root>;
};
  • Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.

    Parameter filename

    One or multiple files to load

    Parameter root

    Root namespace, defaults to create a new one if omitted.

    Parameter callback

    Callback function

    See Also

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

    Parameter filename

    One or multiple files to load

    Parameter callback

    Callback function

    See Also

  • Loads one or multiple .proto or preprocessed .json files into a common root namespace and returns a promise.

    Parameter filename

    One or multiple files to load

    Parameter root

    Root namespace, defaults to create a new one if omitted.

    Returns

    Promise

    See Also

function loadSync

loadSync: (filename: string | string[], root?: Root) => Root;
  • Synchronously loads one or multiple .proto or preprocessed .json files into a common root namespace (node only).

    Parameter filename

    One or multiple files to load

    Parameter root

    Root namespace, defaults to create a new one if omitted.

    Returns

    Root namespace

    Throws

    {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid

    See Also

function parse

parse: {
(source: string, options?: IParseOptions): IParserResult;
(source: string, root: Root, options?: IParseOptions): IParserResult;
};
  • Parses the given .proto source and returns an object with the parsed contents.

    Parameter source

    Source contents

    Parameter options

    Parse options. Defaults to parse.defaults when omitted.

    Returns

    Parser result

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

    Parameter source

    Source contents

    Parameter root

    Root to populate

    Parameter options

    Parse options. Defaults to parse.defaults when omitted.

    Returns

    Parser result

function tokenize

tokenize: typeof tokenize;
  • Tokenizes the given .proto source and returns an object with useful utility functions.

    Parameter source

    Source contents

    Parameter alternateCommentMode

    Whether we should activate alternate comment parsing mode.

    Returns

    Tokenizer handle

function verifier

verifier: (mtype: Type) => Codegen;
  • Generates a verifier specific to the specified message type.

    Parameter mtype

    Message type

    Returns

    Codegen instance

Classes

class BufferReader

class BufferReader extends Reader {}
  • Wire format reader using node buffers.

constructor

constructor(buffer: Buffer);
  • Constructs a new buffer reader instance.

    Parameter buffer

    Buffer to read from

method bytes

bytes: () => Buffer;
  • Reads a sequence of bytes preceeded by its length as a varint.

    Returns

    Value read

class BufferWriter

class BufferWriter extends Writer {}
  • Wire format writer using node buffers.

constructor

constructor();
  • Constructs a new buffer writer instance.

method alloc

static alloc: (size: number) => Buffer;
  • Allocates a buffer of the specified size.

    Parameter size

    Buffer size

    Returns

    Buffer

method finish

finish: () => Buffer;
  • Finishes the write operation.

    Returns

    Finished buffer

class Enum

class Enum extends ReflectionObject {}
  • Reflected enum.

constructor

constructor(
name: string,
values?: { [k: string]: number },
options?: { [k: string]: any },
comment?: string,
comments?: { [k: string]: string },
valuesOptions?: { [k: string]: { [k: string]: any } }
);
  • Constructs a new enum instance.

    Parameter name

    Unique name within its namespace

    Parameter values

    Enum values as an object, by name

    Parameter options

    Declared options

    Parameter comment

    The comment for this enum

    Parameter comments

    The value comments for this enum

    Parameter valuesOptions

    The value options for this enum

property comment

comment: string;
  • Enum comment text.

property comments

comments: { [k: string]: string };
  • Value comment texts, if any.

property reserved

reserved: (string | number[])[];
  • Reserved ranges, if any.

property values

values: { [k: string]: number };
  • Enum values by name.

property valuesById

valuesById: { [k: number]: string };
  • Enum values by id.

property valuesOptions

valuesOptions?: { [k: string]: { [k: string]: any } };
  • Values options, if any

method add

add: (
name: string,
id: number,
comment?: string,
options?: { [k: string]: any }
) => Enum;
  • Adds a value to this enum.

    Parameter name

    Value name

    Parameter id

    Value id

    Parameter comment

    Comment, if any

    Parameter options

    Options, if any

    Returns

    this

    Throws

    {TypeError} If arguments are invalid

    Throws

    {Error} If there is already a value with this name or id

method fromJSON

static fromJSON: (name: string, json: IEnum) => Enum;
  • Constructs an enum from an enum descriptor.

    Parameter name

    Enum name

    Parameter json

    Enum descriptor

    Returns

    Created enum

    Throws

    {TypeError} If arguments are invalid

method isReservedId

isReservedId: (id: number) => boolean;
  • Tests if the specified id is reserved.

    Parameter id

    Id to test

    Returns

    true if reserved, otherwise false

method isReservedName

isReservedName: (name: string) => boolean;
  • Tests if the specified name is reserved.

    Parameter name

    Name to test

    Returns

    true if reserved, otherwise false

method remove

remove: (name: string) => Enum;
  • Removes a value from this enum

    Parameter name

    Value name

    Returns

    this

    Throws

    {TypeError} If arguments are invalid

    Throws

    {Error} If name is not a name of this enum

method toJSON

toJSON: (toJSONOptions?: IToJSONOptions) => IEnum;
  • Converts this enum to an enum descriptor.

    Parameter toJSONOptions

    JSON conversion options

    Returns

    Enum descriptor

class Field

class Field extends FieldBase {}
  • Reflected message field.

constructor

constructor(
name: string,
id: number,
type: string,
rule?: string | { [k: string]: any },
extend?: string | { [k: string]: any },
options?: { [k: string]: any }
);
  • Constructs a new message field instance. Note that map fields have their own class.

    Parameter name

    Unique name within its namespace

    Parameter id

    Unique id within its namespace

    Parameter type

    Value type

    Parameter rule

    Field rule

    Parameter extend

    Extended type if different from parent

    Parameter options

    Declared options

property packed

readonly packed: boolean;
  • Determines whether this field is packed. Only relevant when repeated and working with proto2.

method d

static d: {
<
T extends
| string
| number
| boolean
| Uint8Array
| Long
| string[]
| number[]
| Long[]
| boolean[]
| Uint8Array[]
| Buffer
| Buffer[]
>(
fieldId: number,
fieldType:
| 'double'
| 'float'
| 'int32'
| 'uint32'
| 'sint32'
| 'fixed32'
| 'sfixed32'
| 'int64'
| 'uint64'
| 'sint64'
| 'fixed64'
| 'sfixed64'
| 'string'
| 'bool'
| 'bytes'
| object,
fieldRule?: 'optional' | 'required' | 'repeated',
defaultValue?: T
): FieldDecorator;
<T extends Message<T>>(
fieldId: number,
fieldType: string | Constructor<T>,
fieldRule?: 'optional' | 'required' | 'repeated'
): FieldDecorator;
};
  • Field decorator (TypeScript).

    Parameter fieldId

    Field id

    Parameter fieldType

    Field type

    Parameter fieldRule

    Field rule

    Parameter defaultValue

    Default value

    Returns

    Decorator function

  • Field decorator (TypeScript).

    Parameter fieldId

    Field id

    Parameter fieldType

    Field type

    Parameter fieldRule

    Field rule

    Returns

    Decorator function

method fromJSON

static fromJSON: (name: string, json: IField) => Field;
  • Constructs a field from a field descriptor.

    Parameter name

    Field name

    Parameter json

    Field descriptor

    Returns

    Created field

    Throws

    {TypeError} If arguments are invalid

class FieldBase

class FieldBase extends ReflectionObject {}
  • Base class of all reflected message fields. This is not an actual class but here for the sake of having consistent type definitions.

constructor

constructor(
name: string,
id: number,
type: string,
rule?: string | { [k: string]: any },
extend?: string | { [k: string]: any },
options?: { [k: string]: any },
comment?: string
);
  • Not an actual constructor. Use Field instead.

    Parameter name

    Unique name within its namespace

    Parameter id

    Unique id within its namespace

    Parameter type

    Value type

    Parameter rule

    Field rule

    Parameter extend

    Extended type if different from parent

    Parameter options

    Declared options

    Parameter comment

    Comment associated with this field

property bytes

bytes: boolean;
  • Whether this field's value is a buffer.

property comment

comment: string;
  • Comment for this field.

property declaringField

declaringField: Field;
  • Sister-field within the declaring namespace if an extended field.

property defaultValue

defaultValue: any;
  • The field's default value on prototypes.

property extend

extend?: string;
  • Extended type if different from parent.

property extensionField

extensionField: Field;
  • Sister-field within the extended type if a declaring extension field.

property id

id: number;
  • Unique field id.

property long

long: boolean;
  • Whether this field's value should be treated as a long.

property map

map: boolean;
  • Whether this field is a map or not.

property message

message: Type;
  • Message this field belongs to.

property optional

optional: boolean;
  • Whether this field is optional.

property partOf

partOf: OneOf;
  • OneOf this field belongs to, if any,

property repeated

repeated: boolean;
  • Whether this field is repeated.

property required

required: boolean;
  • Whether this field is required.

property resolvedType

resolvedType: Type | Enum;
  • Resolved type if not a basic type.

property type

type: string;
  • Field type.

property typeDefault

typeDefault: any;
  • The field type's default value.

method resolve

resolve: () => Field;
  • Resolves this field's type references.

    Returns

    this

    Throws

    {Error} If any reference cannot be resolved

method toJSON

toJSON: (toJSONOptions?: IToJSONOptions) => IField;
  • Converts this field to a field descriptor.

    Parameter toJSONOptions

    JSON conversion options

    Returns

    Field descriptor

class MapField

class MapField extends FieldBase {}
  • Reflected map field.

constructor

constructor(
name: string,
id: number,
keyType: string,
type: string,
options?: { [k: string]: any },
comment?: string
);
  • Constructs a new map field instance.

    Parameter name

    Unique name within its namespace

    Parameter id

    Unique id within its namespace

    Parameter keyType

    Key type

    Parameter type

    Value type

    Parameter options

    Declared options

    Parameter comment

    Comment associated with this field

property keyType

keyType: string;
  • Key type.

property resolvedKeyType

resolvedKeyType: ReflectionObject;
  • Resolved key type if not a basic type.

method d

static d: <
T extends {
[key: string]:
| string
| number
| boolean
| Uint8Array
| Long
| number[]
| Buffer
| Message<{}>;
}
>(
fieldId: number,
fieldKeyType:
| 'int32'
| 'uint32'
| 'sint32'
| 'fixed32'
| 'sfixed32'
| 'int64'
| 'uint64'
| 'sint64'
| 'fixed64'
| 'sfixed64'
| 'bool'
| 'string',
fieldValueType:
| 'double'
| 'float'
| 'int32'
| 'uint32'
| 'sint32'
| 'fixed32'
| 'sfixed32'
| 'int64'
| 'uint64'
| 'sint64'
| 'fixed64'
| 'sfixed64'
| 'bool'
| 'string'
| 'bytes'
| object
| Constructor<{}>
) => FieldDecorator;
  • Map field decorator (TypeScript).

    Parameter fieldId

    Field id

    Parameter fieldKeyType

    Field key type

    Parameter fieldValueType

    Field value type

    Returns

    Decorator function

method fromJSON

static fromJSON: (name: string, json: IMapField) => MapField;
  • Constructs a map field from a map field descriptor.

    Parameter name

    Field name

    Parameter json

    Map field descriptor

    Returns

    Created map field

    Throws

    {TypeError} If arguments are invalid

method toJSON

toJSON: (toJSONOptions?: IToJSONOptions) => IMapField;
  • Converts this map field to a map field descriptor.

    Parameter toJSONOptions

    JSON conversion options

    Returns

    Map field descriptor

class Message

class Message<T extends object = object> {}
  • Abstract runtime message.

constructor

constructor(properties?: Properties<T>);
  • Constructs a new message instance.

    Parameter properties

    Properties to set

property $type

static readonly $type: Type;
  • Reference to the reflected type.

property $type

readonly $type: Type;
  • Reference to the reflected type.

method create

static create: <T extends Message<T>>(
this: Constructor<T>,
properties?: { [k: string]: any }
) => Message<T>;
  • Creates a new message of this type using the specified properties.

    Parameter properties

    Properties to set

    Returns

    Message instance

method decode

static decode: <T extends Message<T>>(
this: Constructor<T>,
reader: Reader | Uint8Array
) => T;
  • Decodes a message of this type.

    Parameter reader

    Reader or buffer to decode

    Returns

    Decoded message

method decodeDelimited

static decodeDelimited: <T extends Message<T>>(
this: Constructor<T>,
reader: Reader | Uint8Array
) => T;
  • Decodes a message of this type preceeded by its length as a varint.

    Parameter reader

    Reader or buffer to decode

    Returns

    Decoded message

method encode

static encode: <T extends Message<T>>(
this: Constructor<T>,
message: T | { [k: string]: any },
writer?: Writer
) => Writer;
  • Encodes a message of this type.

    Parameter message

    Message to encode

    Parameter writer

    Writer to use

    Returns

    Writer

method encodeDelimited

static encodeDelimited: <T extends Message<T>>(
this: Constructor<T>,
message: T | { [k: string]: any },
writer?: Writer
) => Writer;
  • Encodes a message of this type preceeded by its length as a varint.

    Parameter message

    Message to encode

    Parameter writer

    Writer to use

    Returns

    Writer

method fromObject

static fromObject: <T extends Message<T>>(
this: Constructor<T>,
object: { [k: string]: any }
) => T;
  • Creates a new message of this type from a plain object. Also converts values to their respective internal types.

    Parameter object

    Plain object

    Returns

    Message instance

method toJSON

toJSON: () => { [k: string]: any };
  • Converts this message to JSON.

    Returns

    JSON object

method toObject

static toObject: <T extends Message<T>>(
this: Constructor<T>,
message: T,
options?: IConversionOptions
) => { [k: string]: any };
  • Creates a plain object from a message of this type. Also converts values to other types if specified.

    Parameter message

    Message instance

    Parameter options

    Conversion options

    Returns

    Plain object

method verify

static verify: (message: { [k: string]: any }) => string | null;
  • Verifies a message of this type.

    Parameter message

    Plain object to verify

    Returns

    null if valid, otherwise the reason why it is not

class Method

class Method extends ReflectionObject {}
  • Reflected service method.

constructor

constructor(
name: string,
type: string,
requestType: string,
responseType: string,
requestStream?: boolean | { [k: string]: any },
responseStream?: boolean | { [k: string]: any },
options?: { [k: string]: any },
comment?: string,
parsedOptions?: { [k: string]: any }
);
  • Constructs a new service method instance.

    Parameter name

    Method name

    Parameter type

    Method type, usually "rpc"

    Parameter requestType

    Request message type

    Parameter responseType

    Response message type

    Parameter requestStream

    Whether the request is streamed

    Parameter responseStream

    Whether the response is streamed

    Parameter options

    Declared options

    Parameter comment

    The comment for this method

    Parameter parsedOptions

    Declared options, properly parsed into an object

property comment

comment: string;
  • Comment for this method

property parsedOptions

parsedOptions: any;
  • Options properly parsed into an object

property requestStream

requestStream?: boolean;
  • Whether requests are streamed or not.

property requestType

requestType: string;
  • Request type.

property resolvedRequestType

resolvedRequestType: Type;
  • Resolved request type.

property resolvedResponseType

resolvedResponseType: Type;
  • Resolved response type.

property responseStream

responseStream?: boolean;
  • Whether responses are streamed or not.

property responseType

responseType: string;
  • Response type.

property type

type: string;
  • Method type.

method fromJSON

static fromJSON: (name: string, json: IMethod) => Method;
  • Constructs a method from a method descriptor.

    Parameter name

    Method name

    Parameter json

    Method descriptor

    Returns

    Created method

    Throws

    {TypeError} If arguments are invalid

method toJSON

toJSON: (toJSONOptions?: IToJSONOptions) => IMethod;
  • Converts this method to a method descriptor.

    Parameter toJSONOptions

    JSON conversion options

    Returns

    Method descriptor

class Namespace

class Namespace extends NamespaceBase {}
  • Reflected namespace.

constructor

constructor(name: string, options?: { [k: string]: any });
  • Constructs a new namespace instance.

    Parameter name

    Namespace name

    Parameter options

    Declared options

method arrayToJSON

static arrayToJSON: (
array: ReflectionObject[],
toJSONOptions?: IToJSONOptions
) => { [k: string]: any };
  • Converts an array of reflection objects to JSON.

    Parameter array

    Object array

    Parameter toJSONOptions

    JSON conversion options

    Returns

    JSON object or undefined when array is empty

method fromJSON

static fromJSON: (name: string, json: { [k: string]: any }) => Namespace;
  • Constructs a namespace from JSON.

    Parameter name

    Namespace name

    Parameter json

    JSON object

    Returns

    Created namespace

    Throws

    {TypeError} If arguments are invalid

method isReservedId

static isReservedId: (
reserved: (number[] | string)[] | undefined,
id: number
) => boolean;
  • Tests if the specified id is reserved.

    Parameter reserved

    Array of reserved ranges and names

    Parameter id

    Id to test

    Returns

    true if reserved, otherwise false

method isReservedName

static isReservedName: (
reserved: (number[] | string)[] | undefined,
name: string
) => boolean;
  • Tests if the specified name is reserved.

    Parameter reserved

    Array of reserved ranges and names

    Parameter name

    Name to test

    Returns

    true if reserved, otherwise false

class NamespaceBase

abstract class NamespaceBase extends ReflectionObject {}
  • Base class of all reflection objects containing nested objects. This is not an actual class but here for the sake of having consistent type definitions.

property nested

nested?: { [k: string]: ReflectionObject };
  • Nested objects by name.

property nestedArray

readonly nestedArray: ReflectionObject[];
  • Nested objects of this namespace as an array for iteration.

method add

add: (object: ReflectionObject) => Namespace;
  • Adds a nested object to this namespace.

    Parameter object

    Nested object to add

    Returns

    this

    Throws

    {TypeError} If arguments are invalid

    Throws

    {Error} If there is already a nested object with this name

method addJSON

addJSON: (nestedJson: { [k: string]: AnyNestedObject }) => Namespace;
  • Adds nested objects to this namespace from nested object descriptors.

    Parameter nestedJson

    Any nested object descriptors

    Returns

    this

method define

define: (path: string | string[], json?: any) => Namespace;
  • Defines additial namespaces within this one if not yet existing.

    Parameter path

    Path to create

    Parameter json

    Nested types to create from JSON

    Returns

    Pointer to the last namespace created or this if path is empty

method get

get: (name: string) => ReflectionObject | null;
  • Gets the nested object of the specified name.

    Parameter name

    Nested object name

    Returns

    The reflection object or null if it doesn't exist

method getEnum

getEnum: (name: string) => { [k: string]: number };
  • Gets the values of the nested enum of the specified name. This methods differs from get in that it returns an enum's values directly and throws instead of returning null.

    Parameter name

    Nested enum name

    Returns

    Enum values

    Throws

    {Error} If there is no such enum

method lookup

lookup: {
(
path: string | string[],
filterTypes: any | any[],
parentAlreadyChecked?: boolean
): ReflectionObject | null;
(path: string | string[], parentAlreadyChecked?: boolean): ReflectionObject;
};
  • Recursively looks up the reflection object matching the specified path in the scope of this namespace.

    Parameter path

    Path to look up

    Parameter filterTypes

    Filter types, any combination of the constructors of protobuf.Type, protobuf.Enum, protobuf.Service etc.

    Parameter parentAlreadyChecked

    If known, whether the parent has already been checked

    Returns

    Looked up object or null if none could be found

  • Looks up the reflection object at the specified path, relative to this namespace.

    Parameter path

    Path to look up

    Parameter parentAlreadyChecked

    Whether the parent has already been checked

    Returns

    Looked up object or null if none could be found

method lookupEnum

lookupEnum: (path: string | string[]) => Enum;
  • Looks up the values of the enum at the specified path, relative to this namespace. Besides its signature, this methods differs from lookup in that it throws instead of returning null.

    Parameter path

    Path to look up

    Returns

    Looked up enum

    Throws

    {Error} If path does not point to an enum

method lookupService

lookupService: (path: string | string[]) => Service;
  • Looks up the service at the specified path, relative to this namespace. Besides its signature, this methods differs from lookup in that it throws instead of returning null.

    Parameter path

    Path to look up

    Returns

    Looked up service

    Throws

    {Error} If path does not point to a service

method lookupType

lookupType: (path: string | string[]) => Type;
  • Looks up the type at the specified path, relative to this namespace. Besides its signature, this methods differs from lookup in that it throws instead of returning null.

    Parameter path

    Path to look up

    Returns

    Looked up type

    Throws

    {Error} If path does not point to a type

method lookupTypeOrEnum

lookupTypeOrEnum: (path: string | string[]) => Type;
  • Looks up the type or enum at the specified path, relative to this namespace. Besides its signature, this methods differs from lookup in that it throws instead of returning null.

    Parameter path

    Path to look up

    Returns

    Looked up type or enum

    Throws

    {Error} If path does not point to a type or enum

method remove

remove: (object: ReflectionObject) => Namespace;
  • Removes a nested object from this namespace.

    Parameter object

    Nested object to remove

    Returns

    this

    Throws

    {TypeError} If arguments are invalid

    Throws

    {Error} If object is not a member of this namespace

method resolveAll

resolveAll: () => Namespace;
  • Resolves this namespace's and all its nested objects' type references. Useful to validate a reflection tree, but comes at a cost.

    Returns

    this

method toJSON

toJSON: (toJSONOptions?: IToJSONOptions) => INamespace;
  • Converts this namespace to a namespace descriptor.

    Parameter toJSONOptions

    JSON conversion options

    Returns

    Namespace descriptor

class OneOf

class OneOf extends ReflectionObject {}
  • Reflected oneof.

constructor

constructor(
name: string,
fieldNames?: string[] | { [k: string]: any },
options?: { [k: string]: any },
comment?: string
);
  • Constructs a new oneof instance.

    Parameter name

    Oneof name

    Parameter fieldNames

    Field names

    Parameter options

    Declared options

    Parameter comment

    Comment associated with this field

property comment

comment: string;
  • Comment for this field.

property fieldsArray

readonly fieldsArray: Field[];
  • Fields that belong to this oneof as an array for iteration.

property oneof

oneof: string[];
  • Field names that belong to this oneof.

method add

add: (field: Field) => OneOf;
  • Adds a field to this oneof and removes it from its current parent, if any.

    Parameter field

    Field to add

    Returns

    this

method d

static d: <T extends string>(...fieldNames: string[]) => OneOfDecorator;
  • OneOf decorator (TypeScript).

    Parameter fieldNames

    Field names

    Returns

    Decorator function

method fromJSON

static fromJSON: (name: string, json: IOneOf) => OneOf;
  • Constructs a oneof from a oneof descriptor.

    Parameter name

    Oneof name

    Parameter json

    Oneof descriptor

    Returns

    Created oneof

    Throws

    {TypeError} If arguments are invalid

method remove

remove: (field: Field) => OneOf;
  • Removes a field from this oneof and puts it back to the oneof's parent.

    Parameter field

    Field to remove

    Returns

    this

method toJSON

toJSON: (toJSONOptions?: IToJSONOptions) => IOneOf;
  • Converts this oneof to a oneof descriptor.

    Parameter toJSONOptions

    JSON conversion options

    Returns

    Oneof descriptor

class Reader

class Reader {}
  • Wire format reader using Uint8Array if available, otherwise Array.

constructor

constructor(buffer: Uint8Array);
  • Constructs a new reader instance using the specified buffer.

    Parameter buffer

    Buffer to read from

property buf

buf: Uint8Array;
  • Read buffer.

property len

len: number;
  • Read buffer length.

property pos

pos: number;
  • Read buffer position.

method bool

bool: () => boolean;
  • Reads a varint as a boolean.

    Returns

    Value read

method bytes

bytes: () => Uint8Array;
  • Reads a sequence of bytes preceeded by its length as a varint.

    Returns

    Value read

method create

static create: (buffer: Uint8Array | Buffer) => Reader | BufferReader;
  • Creates a new reader using the specified buffer.

    Parameter buffer

    Buffer to read from

    Returns

    A BufferReader if buffer is a Buffer, otherwise a Reader

    Throws

    {Error} If buffer is not a valid buffer

method double

double: () => number;
  • Reads a double (64 bit float) as a number.

    Returns

    Value read

method fixed32

fixed32: () => number;
  • Reads fixed 32 bits as an unsigned 32 bit integer.

    Returns

    Value read

method fixed64

fixed64: () => Long;
  • Reads fixed 64 bits.

    Returns

    Value read

method float

float: () => number;
  • Reads a float (32 bit) as a number.

    Returns

    Value read

method int32

int32: () => number;
  • Reads a varint as a signed 32 bit value.

    Returns

    Value read

method int64

int64: () => Long;
  • Reads a varint as a signed 64 bit value.

    Returns

    Value read

method sfixed32

sfixed32: () => number;
  • Reads fixed 32 bits as a signed 32 bit integer.

    Returns

    Value read

method sfixed64

sfixed64: () => Long;
  • Reads zig-zag encoded fixed 64 bits.

    Returns

    Value read

method sint32

sint32: () => number;
  • Reads a zig-zag encoded varint as a signed 32 bit value.

    Returns

    Value read

method sint64

sint64: () => Long;
  • Reads a zig-zag encoded varint as a signed 64 bit value.

    Returns

    Value read

method skip

skip: (length?: number) => Reader;
  • Skips the specified number of bytes if specified, otherwise skips a varint.

    Parameter length

    Length if known, otherwise a varint is assumed

    Returns

    this

method skipType

skipType: (wireType: number) => Reader;
  • Skips the next element of the specified wire type.

    Parameter wireType

    Wire type received

    Returns

    this

method string

string: () => string;
  • Reads a string preceeded by its byte length as a varint.

    Returns

    Value read

method uint32

uint32: () => number;
  • Reads a varint as an unsigned 32 bit value.

    Returns

    Value read

method uint64

uint64: () => Long;
  • Reads a varint as an unsigned 64 bit value.

    Returns

    Value read

class ReflectionObject

abstract class ReflectionObject {}
  • Base class of all reflection objects.

property comment

comment: string;
  • Comment text, if any.

property filename

filename: string;
  • Defining file name.

property fullName

readonly fullName: string;
  • Full name including leading dot.

property name

name: string;
  • Unique name within its namespace.

property options

options?: { [k: string]: any };
  • Options.

property parent

parent: Namespace;
  • Parent namespace.

property parsedOptions

parsedOptions?: { [k: string]: any[] };
  • Parsed Options.

property resolved

resolved: boolean;
  • Whether already resolved or not.

property root

readonly root: Root;
  • Reference to the root namespace.

method getOption

getOption: (name: string) => any;
  • Gets an option value.

    Parameter name

    Option name

    Returns

    Option value or undefined if not set

method onAdd

onAdd: (parent: ReflectionObject) => void;
  • Called when this object is added to a parent.

    Parameter parent

    Parent added to

method onRemove

onRemove: (parent: ReflectionObject) => void;
  • Called when this object is removed from a parent.

    Parameter parent

    Parent removed from

method resolve

resolve: () => ReflectionObject;
  • Resolves this objects type references.

    Returns

    this

method setOption

setOption: (name: string, value: any, ifNotSet?: boolean) => ReflectionObject;
  • Sets an option.

    Parameter name

    Option name

    Parameter value

    Option value

    Parameter ifNotSet

    Sets the option only if it isn't currently set

    Returns

    this

method setOptions

setOptions: (
options: { [k: string]: any },
ifNotSet?: boolean
) => ReflectionObject;
  • Sets multiple options.

    Parameter options

    Options to set

    Parameter ifNotSet

    Sets an option only if it isn't currently set

    Returns

    this

method setParsedOption

setParsedOption: (
name: string,
value: any,
propName: string
) => ReflectionObject;
  • Sets a parsed option.

    Parameter name

    parsed Option name

    Parameter value

    Option value

    Parameter propName

    dot '.' delimited full path of property within the option to set. if undefined\empty, will add a new option with that value

    Returns

    this

method toJSON

toJSON: () => { [k: string]: any };
  • Converts this reflection object to its descriptor representation.

    Returns

    Descriptor

method toString

toString: () => string;
  • Converts this instance to its string representation.

    Returns

    Class name[, space, full name]

class Root

class Root extends NamespaceBase {}
  • Root namespace wrapping all types, enums, services, sub-namespaces etc. that belong together.

constructor

constructor(options?: { [k: string]: any });
  • Constructs a new root namespace instance.

    Parameter options

    Top level options

property deferred

deferred: Field[];
  • Deferred extension fields.

property files

files: string[];
  • Resolved file names of loaded files.

method fetch

fetch: (path: string, callback: FetchCallback) => void;
  • Fetch content from file path or url This method exists so you can override it with your own logic.

    Parameter path

    File path or url

    Parameter callback

    Callback function

method fromJSON

static fromJSON: (json: INamespace, root?: Root) => Root;
  • Loads a namespace descriptor into a root namespace.

    Parameter json

    Nameespace descriptor

    Parameter root

    Root namespace, defaults to create a new one if omitted

    Returns

    Root namespace

method load

load: {
(
filename: string | string[],
options: IParseOptions,
callback: LoadCallback
): void;
(filename: string | string[], callback: LoadCallback): void;
(filename: string | string[], options?: IParseOptions): Promise<Root>;
};
  • Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.

    Parameter filename

    Names of one or multiple files to load

    Parameter options

    Parse options

    Parameter callback

    Callback function

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

    Parameter filename

    Names of one or multiple files to load

    Parameter callback

    Callback function

  • Loads one or multiple .proto or preprocessed .json files into this root namespace and returns a promise.

    Parameter filename

    Names of one or multiple files to load

    Parameter options

    Parse options. Defaults to parse.defaults when omitted.

    Returns

    Promise

method loadSync

loadSync: (filename: string | string[], options?: IParseOptions) => Root;
  • Synchronously loads one or multiple .proto or preprocessed .json files into this root namespace (node only).

    Parameter filename

    Names of one or multiple files to load

    Parameter options

    Parse options. Defaults to parse.defaults when omitted.

    Returns

    Root namespace

    Throws

    {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid

method resolvePath

resolvePath: (origin: string, target: string) => string | null;
  • Resolves the path of an imported file, relative to the importing origin. This method exists so you can override it with your own logic in case your imports are scattered over multiple directories.

    Parameter origin

    The file name of the importing file

    Parameter target

    The file name being imported

    Returns

    Resolved path to target or null to skip the file

class Service

class Service extends NamespaceBase {}
  • Reflected service.

constructor

constructor(name: string, options?: { [k: string]: any });
  • Constructs a new service instance.

    Parameter name

    Service name

    Parameter options

    Service options

    Throws

    {TypeError} If arguments are invalid

property methods

methods: { [k: string]: Method };
  • Service methods.

property methodsArray

readonly methodsArray: Method[];
  • Methods of this service as an array for iteration.

method create

create: (
rpcImpl: RPCImpl,
requestDelimited?: boolean,
responseDelimited?: boolean
) => rpc.Service;
  • Creates a runtime service using the specified rpc implementation.

    Parameter rpcImpl

    RPC implementation

    Parameter requestDelimited

    Whether requests are length-delimited

    Parameter responseDelimited

    Whether responses are length-delimited

    Returns

    RPC service. Useful where requests and/or responses are streamed.

method fromJSON

static fromJSON: (name: string, json: IService) => Service;
  • Constructs a service from a service descriptor.

    Parameter name

    Service name

    Parameter json

    Service descriptor

    Returns

    Created service

    Throws

    {TypeError} If arguments are invalid

method toJSON

toJSON: (toJSONOptions?: IToJSONOptions) => IService;
  • Converts this service to a service descriptor.

    Parameter toJSONOptions

    JSON conversion options

    Returns

    Service descriptor

class Type

class Type extends NamespaceBase {}
  • Reflected message type.

constructor

constructor(name: string, options?: { [k: string]: any });
  • Constructs a new reflected message type instance.

    Parameter name

    Message name

    Parameter options

    Declared options

property ctor

ctor: Constructor<{}>;
  • The registered constructor, if any registered, otherwise a generic constructor. Assigning a function replaces the internal constructor. If the function does not extend Message yet, its prototype will be setup accordingly and static methods will be populated. If it already extends Message, it will just replace the internal constructor.

property extensions

extensions: number[][];
  • Extension ranges, if any.

property fields

fields: { [k: string]: Field };
  • Message fields.

property fieldsArray

readonly fieldsArray: Field[];
  • Fields of this message as an array for iteration.

property fieldsById

readonly fieldsById: { [k: number]: Field };
  • Message fields by id.

property oneofs

oneofs: { [k: string]: OneOf };
  • Oneofs declared within this namespace, if any.

property oneofsArray

readonly oneofsArray: OneOf[];
  • Oneofs of this message as an array for iteration.

property reserved

reserved: (string | number[])[];
  • Reserved ranges, if any.

method add

add: (object: ReflectionObject) => Type;
  • Adds a nested object to this type.

    Parameter object

    Nested object to add

    Returns

    this

    Throws

    {TypeError} If arguments are invalid

    Throws

    {Error} If there is already a nested object with this name or, if a field, when there is already a field with this id

method create

create: (properties?: { [k: string]: any }) => Message<{}>;
  • Creates a new message of this type using the specified properties.

    Parameter properties

    Properties to set

    Returns

    Message instance

method d

static d: <T extends Message<T>>(typeName?: string) => TypeDecorator<T>;
  • Type decorator (TypeScript).

    Parameter typeName

    Type name, defaults to the constructor's name

    Returns

    Decorator function

method decode

decode: (reader: Reader | Uint8Array, length?: number) => Message<{}>;
  • Decodes a message of this type.

    Parameter reader

    Reader or buffer to decode from

    Parameter length

    Length of the message, if known beforehand

    Returns

    Decoded message

    Throws

    {Error} If the payload is not a reader or valid buffer

    Throws

    {util.ProtocolError<{}>} If required fields are missing

method decodeDelimited

decodeDelimited: (reader: Reader | Uint8Array) => Message<{}>;
  • Decodes a message of this type preceeded by its byte length as a varint.

    Parameter reader

    Reader or buffer to decode from

    Returns

    Decoded message

    Throws

    {Error} If the payload is not a reader or valid buffer

    Throws

    {util.ProtocolError} If required fields are missing

method encode

encode: (message: Message<{}> | { [k: string]: any }, writer?: Writer) => Writer;
  • Encodes a message of this type. Does not implicitly verify messages.

    Parameter message

    Message instance or plain object

    Parameter writer

    Writer to encode to

    Returns

    writer

method encodeDelimited

encodeDelimited: (
message: Message<{}> | { [k: string]: any },
writer?: Writer
) => Writer;
  • Encodes a message of this type preceeded by its byte length as a varint. Does not implicitly verify messages.

    Parameter message

    Message instance or plain object

    Parameter writer

    Writer to encode to

    Returns

    writer

method fromJSON

static fromJSON: (name: string, json: IType) => Type;
  • Creates a message type from a message type descriptor.

    Parameter name

    Message name

    Parameter json

    Message type descriptor

    Returns

    Created message type

method fromObject

fromObject: (object: { [k: string]: any }) => Message<{}>;
  • Creates a new message of this type from a plain object. Also converts values to their respective internal types.

    Parameter object

    Plain object to convert

    Returns

    Message instance

method generateConstructor

static generateConstructor: (mtype: Type) => Codegen;
  • Generates a constructor function for the specified type.

    Parameter mtype

    Message type

    Returns

    Codegen instance

method isReservedId

isReservedId: (id: number) => boolean;
  • Tests if the specified id is reserved.

    Parameter id

    Id to test

    Returns

    true if reserved, otherwise false

method isReservedName

isReservedName: (name: string) => boolean;
  • Tests if the specified name is reserved.

    Parameter name

    Name to test

    Returns

    true if reserved, otherwise false

method remove

remove: (object: ReflectionObject) => Type;
  • Removes a nested object from this type.

    Parameter object

    Nested object to remove

    Returns

    this

    Throws

    {TypeError} If arguments are invalid

    Throws

    {Error} If object is not a member of this type

method setup

setup: () => Type;

method toJSON

toJSON: (toJSONOptions?: IToJSONOptions) => IType;
  • Converts this message type to a message type descriptor.

    Parameter toJSONOptions

    JSON conversion options

    Returns

    Message type descriptor

method toObject

toObject: (
message: Message<{}>,
options?: IConversionOptions
) => { [k: string]: any };
  • Creates a plain object from a message of this type. Also converts values to other types if specified.

    Parameter message

    Message instance

    Parameter options

    Conversion options

    Returns

    Plain object

method verify

verify: (message: { [k: string]: any }) => null | string;
  • Verifies that field values are valid and that required fields are present.

    Parameter message

    Plain object to verify

    Returns

    null if valid, otherwise the reason why it is not

class Writer

class Writer {}
  • Wire format writer using Uint8Array if available, otherwise Array.

constructor

constructor();
  • Constructs a new writer instance.

property head

head: {};
  • Operations head.

property len

len: number;
  • Current length.

property states

states: {};
  • Linked forked states.

property tail

tail: {};
  • Operations tail

method alloc

static alloc: (size: number) => Uint8Array;
  • Allocates a buffer of the specified size.

    Parameter size

    Buffer size

    Returns

    Buffer

method bool

bool: (value: boolean) => Writer;
  • Writes a boolish value as a varint.

    Parameter value

    Value to write

    Returns

    this

method bytes

bytes: (value: Uint8Array | string) => Writer;
  • Writes a sequence of bytes.

    Parameter value

    Buffer or base64 encoded string to write

    Returns

    this

method create

static create: () => BufferWriter | Writer;

method double

double: (value: number) => Writer;
  • Writes a double (64 bit float).

    Parameter value

    Value to write

    Returns

    this

method finish

finish: () => Uint8Array;
  • Finishes the write operation.

    Returns

    Finished buffer

method fixed32

fixed32: (value: number) => Writer;
  • Writes an unsigned 32 bit value as fixed 32 bits.

    Parameter value

    Value to write

    Returns

    this

method fixed64

fixed64: (value: Long | number | string) => Writer;
  • Writes an unsigned 64 bit value as fixed 64 bits.

    Parameter value

    Value to write

    Returns

    this

    Throws

    {TypeError} If value is a string and no long library is present.

method float

float: (value: number) => Writer;
  • Writes a float (32 bit).

    Parameter value

    Value to write

    Returns

    this

method fork

fork: () => Writer;
  • Forks this writer's state by pushing it to a stack. Calling reset or ldelim resets the writer to the previous state.

    Returns

    this

method int32

int32: (value: number) => Writer;
  • Writes a signed 32 bit value as a varint.

    Parameter value

    Value to write

    Returns

    this

method int64

int64: (value: Long | number | string) => Writer;
  • Writes a signed 64 bit value as a varint.

    Parameter value

    Value to write

    Returns

    this

    Throws

    {TypeError} If value is a string and no long library is present.

method ldelim

ldelim: () => Writer;
  • Resets to the last state and appends the fork state's current write length as a varint followed by its operations.

    Returns

    this

method reset

reset: () => Writer;
  • Resets this instance to the last state.

    Returns

    this

method sfixed32

sfixed32: (value: number) => Writer;
  • Writes a signed 32 bit value as fixed 32 bits.

    Parameter value

    Value to write

    Returns

    this

method sfixed64

sfixed64: (value: Long | number | string) => Writer;
  • Writes a signed 64 bit value as fixed 64 bits.

    Parameter value

    Value to write

    Returns

    this

    Throws

    {TypeError} If value is a string and no long library is present.

method sint32

sint32: (value: number) => Writer;
  • Writes a 32 bit value as a varint, zig-zag encoded.

    Parameter value

    Value to write

    Returns

    this

method sint64

sint64: (value: Long | number | string) => Writer;
  • Writes a signed 64 bit value as a varint, zig-zag encoded.

    Parameter value

    Value to write

    Returns

    this

    Throws

    {TypeError} If value is a string and no long library is present.

method string

string: (value: string) => Writer;
  • Writes a string.

    Parameter value

    Value to write

    Returns

    this

method uint32

uint32: (value: number) => Writer;
  • Writes an unsigned 32 bit value as a varint.

    Parameter value

    Value to write

    Returns

    this

method uint64

uint64: (value: Long | number | string) => Writer;
  • Writes an unsigned 64 bit value as a varint.

    Parameter value

    Value to write

    Returns

    this

    Throws

    {TypeError} If value is a string and no long library is present.

Interfaces

interface Buffer

interface Buffer extends Uint8Array {}
  • Any compatible Buffer instance. This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.

interface Constructor

interface Constructor<T> extends Function {}
  • Constructor type.

property prototype

prototype: T;

    construct signature

    new (...params: any[]): T;

      interface IConversionOptions

      interface IConversionOptions {}

      property arrays

      arrays?: boolean;
      • Sets empty arrays for missing repeated fields even if defaults=false

      property bytes

      bytes?: Function;
      • Bytes value conversion type. Valid values are Array and (a base64 encoded) String (the global types). Defaults to copy the present value, which usually is a Buffer under node and an Uint8Array in the browser.

      property defaults

      defaults?: boolean;
      • Also sets default values on the resulting object

      property enums

      enums?: Function;
      • Enum value conversion type. Only valid value is String (the global type). Defaults to copy the present value, which is the numeric id.

      property json

      json?: boolean;
      • Performs additional JSON compatibility conversions, i.e. NaN and Infinity to strings

      property longs

      longs?: Function;
      • Long conversion type. Valid values are String and Number (the global types). Defaults to copy the present value, which is a possibly unsafe number without and a Long with a long library.

      property objects

      objects?: boolean;
      • Sets empty objects for missing map fields even if defaults=false

      property oneofs

      oneofs?: boolean;
      • Includes virtual oneof properties set to the present field's name, if any

      interface IEnum

      interface IEnum {}
      • Enum descriptor.

      property options

      options?: { [k: string]: any };
      • Enum options

      property values

      values: { [k: string]: number };
      • Enum values

      interface IExtensionField

      interface IExtensionField extends IField {}
      • Extension field descriptor.

      property extend

      extend: string;
      • Extended type

      interface IExtensionMapField

      interface IExtensionMapField extends IMapField {}
      • Extension map field descriptor.

      property extend

      extend: string;
      • Extended type

      interface IFetchOptions

      interface IFetchOptions {}

      property binary

      binary?: boolean;
      • Whether expecting a binary response

      property xhr

      xhr?: boolean;
      • If true, forces the use of XMLHttpRequest

      interface IField

      interface IField {}
      • Field descriptor.

      property id

      id: number;
      • Field id

      property options

      options?: { [k: string]: any };
      • Field options

      property rule

      rule?: string;
      • Field rule

      property type

      type: string;
      • Field type

      interface IMapField

      interface IMapField extends IField {}
      • Map field descriptor.

      property keyType

      keyType: string;
      • Key type

      interface IMethod

      interface IMethod {}
      • Method descriptor.

      property comment

      comment: string;
      • Method comments

      property options

      options?: { [k: string]: any };
      • Method options

      property parsedOptions

      parsedOptions?: { [k: string]: any };
      • Method options properly parsed into an object

      property requestStream

      requestStream?: boolean;
      • Whether requests are streamed

      property requestType

      requestType: string;
      • Request type

      property responseStream

      responseStream?: boolean;
      • Whether responses are streamed

      property responseType

      responseType: string;
      • Response type

      property type

      type?: string;
      • Method type

      interface INamespace

      interface INamespace {}
      • Namespace descriptor.

      property nested

      nested?: { [k: string]: AnyNestedObject };
      • Nested object descriptors

      property options

      options?: { [k: string]: any };
      • Namespace options

      interface IOneOf

      interface IOneOf {}
      • Oneof descriptor.

      property oneof

      oneof: string[];
      • Oneof field names

      property options

      options?: { [k: string]: any };
      • Oneof options

      interface IParseOptions

      interface IParseOptions {}
      • Options modifying the behavior of parse.

      property alternateCommentMode

      alternateCommentMode?: boolean;
      • Recognize double-slash comments in addition to doc-block comments.

      property keepCase

      keepCase?: boolean;
      • Keeps field casing instead of converting to camel case

      property preferTrailingComment

      preferTrailingComment?: boolean;
      • Use trailing comment when both leading comment and trailing comment exist.

      interface IParserResult

      interface IParserResult {}
      • Result object returned from parse.

      property imports

      imports: string[] | undefined;
      • Imports, if any

      property package

      package: string | undefined;
      • Package name, if declared

      property root

      root: Root;
      • Populated root instance

      property syntax

      syntax: string | undefined;
      • Syntax, if specified (either "proto2" or "proto3")

      property weakImports

      weakImports: string[] | undefined;
      • Weak imports, if any

      interface IService

      interface IService extends INamespace {}
      • Service descriptor.

      property methods

      methods: { [k: string]: IMethod };
      • Method descriptors

      interface IToJSONOptions

      interface IToJSONOptions {}
      • Options modifying the behavior of JSON serialization.

      property keepComments

      keepComments?: boolean;
      • Serializes comments.

      interface ITokenizerHandle

      interface ITokenizerHandle {}

      property cmnt

      cmnt: TokenizerHandleCmnt;
      • Gets the comment on the previous line or the line comment on the specified line, if any

      property line

      line: number;
      • Current line number

      property next

      next: TokenizerHandleNext;
      • Gets the next token and advances (null on eof)

      property peek

      peek: TokenizerHandlePeek;
      • Peeks for the next token (null on eof)

      property push

      push: TokenizerHandlePush;
      • Pushes a token back to the stack

      property skip

      skip: TokenizerHandleSkip;
      • Skips a token, returns its presence and advances or, if non-optional and not present, throws

      interface IType

      interface IType extends INamespace {}
      • Message type descriptor.

      property extensions

      extensions?: number[][];
      • Extension ranges

      property fields

      fields: { [k: string]: IField };
      • Field descriptors

      property group

      group?: boolean;
      • Whether a legacy group or not

      property oneofs

      oneofs?: { [k: string]: IOneOf };
      • Oneof descriptors

      property reserved

      reserved?: (number[] | string)[];
      • Reserved ranges

      interface IWrapper

      interface IWrapper {}

      property fromObject

      fromObject?: WrapperFromObjectConverter;
      • From object converter

      property toObject

      toObject?: WrapperToObjectConverter;
      • To object converter

      interface Long

      interface Long {}
      • Any compatible Long instance. This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.

      property high

      high: number;
      • High bits

      property low

      low: number;
      • Low bits

      property unsigned

      unsigned: boolean;
      • Whether unsigned or not

      Type Aliases

      type AnyExtensionField

      type AnyExtensionField = IExtensionField | IExtensionMapField;
      • Any extension field descriptor.

      type AnyNestedObject

      type AnyNestedObject =
      | IEnum
      | IType
      | IService
      | AnyExtensionField
      | INamespace
      | IOneOf;
      • Any nested object descriptor.

      type asPromiseCallback

      type asPromiseCallback = (error: Error | null, ...params: any[]) => void;
      • Callback as used by util.asPromise.

        Parameter error

        Error, if any

        Parameter params

        Additional arguments

      type Codegen

      type Codegen = (
      formatStringOrScope?: string | { [k: string]: any },
      ...formatParams: any[]
      ) => Codegen | Function;
      • Appends code to the function's body or finishes generation.

        Parameter formatStringOrScope

        Format string or, to finish the function, an object of additional scope variables, if any

        Parameter formatParams

        Format parameters

        Returns

        Itself or the generated function if finished

        Throws

        {Error} If format parameter counts do not match

      type EventEmitterListener

      type EventEmitterListener = (...args: any[]) => void;

      type FetchCallback

      type FetchCallback = (error: Error, contents?: string) => void;
      • Node-style callback as used by util.fetch.

        Parameter error

        Error, if any, otherwise null

        Parameter contents

        File contents, if there hasn't been an error

      type FieldDecorator

      type FieldDecorator = (prototype: object, fieldName: string) => void;
      • Decorator function as returned by Field.d and MapField.d (TypeScript).

        Parameter prototype

        Target prototype

        Parameter fieldName

        Field name

      type LoadCallback

      type LoadCallback = (error: Error | null, root?: Root) => void;
      • A node-style callback as used by load and Root#load.

        Parameter error

        Error, if any, otherwise null

        Parameter root

        Root, if there hasn't been an error

      type OneOfDecorator

      type OneOfDecorator = (prototype: object, oneofName: string) => void;
      • Decorator function as returned by OneOf.d (TypeScript).

        Parameter prototype

        Target prototype

        Parameter oneofName

        OneOf name

      type OneOfGetter

      type OneOfGetter = () => string | undefined;

      type OneOfSetter

      type OneOfSetter = (value: string | undefined) => void;

      type PoolAllocator

      type PoolAllocator = (size: number) => Uint8Array;
      • An allocator as used by util.pool.

        Parameter size

        Buffer size

        Returns

        Buffer

      type PoolSlicer

      type PoolSlicer = (this: Uint8Array, start: number, end: number) => Uint8Array;
      • A slicer as used by util.pool.

        Parameter start

        Start offset

        Parameter end

        End offset

        Returns

        Buffer slice

      type Properties

      type Properties<T> = { [P in keyof T]?: T[P] };
      • Properties type.

      type RPCImpl

      type RPCImpl = (
      method: Method | rpc.ServiceMethod<Message<{}>, Message<{}>>,
      requestData: Uint8Array,
      callback: RPCImplCallback
      ) => void;
      • RPC implementation passed to Service#create performing a service request on network level, i.e. by utilizing http requests or websockets.

        Parameter method

        Reflected or static method being called

        Parameter requestData

        Request data

        Parameter callback

        Callback function

      type RPCImplCallback

      type RPCImplCallback = (error: Error | null, response?: Uint8Array | null) => void;
      • Node-style callback as used by RPCImpl.

        Parameter error

        Error, if any, otherwise null

        Parameter response

        Response data or null to signal end of stream, if there hasn't been an error

      type TokenizerHandleCmnt

      type TokenizerHandleCmnt = (line?: number) => string | null;
      • Gets the comment on the previous line or, alternatively, the line comment on the specified line.

        Parameter line

        Line number

        Returns

        Comment text or null if none

      type TokenizerHandleNext

      type TokenizerHandleNext = () => string | null;
      • Gets the next token and advances.

        Returns

        Next token or null on eof

      type TokenizerHandlePeek

      type TokenizerHandlePeek = () => string | null;
      • Peeks for the next token.

        Returns

        Next token or null on eof

      type TokenizerHandlePush

      type TokenizerHandlePush = (token: string) => void;
      • Pushes a token back to the stack.

        Parameter token

        Token

      type TokenizerHandleSkip

      type TokenizerHandleSkip = (expected: string, optional?: boolean) => boolean;
      • Skips the next token.

        Parameter expected

        Expected token

        Parameter optional

        If optional

        Returns

        Whether the token matched

        Throws

        {Error} If the token didn't match and is not optional

      type TypeDecorator

      type TypeDecorator<T extends Message<T>> = (target: Constructor<T>) => void;
      • Decorator function as returned by Type.d (TypeScript).

        Parameter target

        Target constructor

      type WrapperFromObjectConverter

      type WrapperFromObjectConverter = (
      this: Type,
      object: { [k: string]: any }
      ) => Message<{}>;
      • From object converter part of an IWrapper.

        Parameter object

        Plain object

        Returns

        Message instance

      type WrapperToObjectConverter

      type WrapperToObjectConverter = (
      this: Type,
      message: Message<{}>,
      options?: IConversionOptions
      ) => { [k: string]: any };
      • To object converter part of an IWrapper.

        Parameter message

        Message instance

        Parameter options

        Conversion options

        Returns

        Plain object

      Namespaces

      namespace common

      namespace common {}

        function get

        get: (file: string) => INamespace | null;
        • Gets the root definition of the specified common proto file.

          Bundled definitions are: - google/protobuf/any.proto - google/protobuf/duration.proto - google/protobuf/empty.proto - google/protobuf/field_mask.proto - google/protobuf/struct.proto - google/protobuf/timestamp.proto - google/protobuf/wrappers.proto

          Parameter file

          Proto file name

          Returns

          Root definition or null if not defined

        interface IAny

        interface IAny {}
        • Properties of a google.protobuf.Any message.

        property bytes

        bytes?: Uint8Array;

          property typeUrl

          typeUrl?: string;

            interface IBoolValue

            interface IBoolValue {}
            • Properties of a google.protobuf.BoolValue message.

            property value

            value?: boolean;

              interface IBytesValue

              interface IBytesValue {}
              • Properties of a google.protobuf.BytesValue message.

              property value

              value?: Uint8Array;

                interface IDoubleValue

                interface IDoubleValue {}
                • Properties of a google.protobuf.DoubleValue message.

                property value

                value?: number;

                  interface IDuration

                  interface IDuration {}
                  • Properties of a google.protobuf.Duration message.

                  property nanos

                  nanos?: number;

                    property seconds

                    seconds?: number | Long;

                      interface IEmpty

                      interface IEmpty {}
                      • Properties of a google.protobuf.Empty message.

                      interface IFloatValue

                      interface IFloatValue {}
                      • Properties of a google.protobuf.FloatValue message.

                      property value

                      value?: number;

                        interface IInt32Value

                        interface IInt32Value {}
                        • Properties of a google.protobuf.Int32Value message.

                        property value

                        value?: number;

                          interface IInt64Value

                          interface IInt64Value {}
                          • Properties of a google.protobuf.Int64Value message.

                          property value

                          value?: number | Long;

                            interface IListValue

                            interface IListValue {}
                            • Properties of a google.protobuf.ListValue message.

                            property values

                            values?: IValue[];

                              interface IStringValue

                              interface IStringValue {}
                              • Properties of a google.protobuf.StringValue message.

                              property value

                              value?: string;

                                interface IStruct

                                interface IStruct {}
                                • Properties of a google.protobuf.Struct message.

                                property fields

                                fields?: { [k: string]: IValue };

                                  interface ITimestamp

                                  interface ITimestamp {}
                                  • Properties of a google.protobuf.Timestamp message.

                                  property nanos

                                  nanos?: number;

                                    property seconds

                                    seconds?: number | Long;

                                      interface IUInt32Value

                                      interface IUInt32Value {}
                                      • Properties of a google.protobuf.UInt32Value message.

                                      property value

                                      value?: number;

                                        interface IUInt64Value

                                        interface IUInt64Value {}
                                        • Properties of a google.protobuf.UInt64Value message.

                                        property value

                                        value?: number | Long;

                                          interface IValue

                                          interface IValue {}
                                          • Properties of a google.protobuf.Value message.

                                          property boolValue

                                          boolValue?: boolean;

                                            property kind

                                            kind?: string;

                                              property listValue

                                              listValue?: IListValue;

                                                property nullValue

                                                nullValue?: 0;

                                                  property numberValue

                                                  numberValue?: number;

                                                    property stringValue

                                                    stringValue?: string;

                                                      property structValue

                                                      structValue?: IStruct;

                                                        namespace converter

                                                        namespace converter {}
                                                        • Runtime message from/to plain object converters.

                                                        function fromObject

                                                        fromObject: (mtype: Type) => Codegen;
                                                        • Generates a plain object to runtime message converter specific to the specified message type.

                                                          Parameter mtype

                                                          Message type

                                                          Returns

                                                          Codegen instance

                                                        function toObject

                                                        toObject: (mtype: Type) => Codegen;
                                                        • Generates a runtime message to plain object converter specific to the specified message type.

                                                          Parameter mtype

                                                          Message type

                                                          Returns

                                                          Codegen instance

                                                        namespace rpc

                                                        namespace rpc {}
                                                        • Streaming RPC helpers.

                                                        class Service

                                                        class Service extends util.EventEmitter {}

                                                        constructor

                                                        constructor(
                                                        rpcImpl: RPCImpl,
                                                        requestDelimited?: boolean,
                                                        responseDelimited?: boolean
                                                        );
                                                        • Constructs a new RPC service instance.

                                                          Parameter rpcImpl

                                                          RPC implementation

                                                          Parameter requestDelimited

                                                          Whether requests are length-delimited

                                                          Parameter responseDelimited

                                                          Whether responses are length-delimited

                                                        property requestDelimited

                                                        requestDelimited: boolean;
                                                        • Whether requests are length-delimited.

                                                        property responseDelimited

                                                        responseDelimited: boolean;
                                                        • Whether responses are length-delimited.

                                                        property rpcImpl

                                                        rpcImpl: RPCImpl;
                                                        • RPC implementation. Becomes null once the service is ended.

                                                        method end

                                                        end: (endedByRPC?: boolean) => rpc.Service;
                                                        • Ends this service and emits the end event.

                                                          Parameter endedByRPC

                                                          Whether the service has been ended by the RPC implementation.

                                                          Returns

                                                          this

                                                        method rpcCall

                                                        rpcCall: <TReq extends Message<TReq>, TRes extends Message<TRes>>(
                                                        method: Method | rpc.ServiceMethod<TReq, TRes>,
                                                        requestCtor: Constructor<TReq>,
                                                        responseCtor: Constructor<TRes>,
                                                        request: TReq | Properties<TReq>,
                                                        callback: rpc.ServiceMethodCallback<TRes>
                                                        ) => void;
                                                        • Calls a service method through rpcImpl.

                                                          Parameter method

                                                          Reflected or static method

                                                          Parameter requestCtor

                                                          Request constructor

                                                          Parameter responseCtor

                                                          Response constructor

                                                          Parameter request

                                                          Request message or plain object

                                                          Parameter callback

                                                          Service callback

                                                        type ServiceMethod

                                                        type ServiceMethod<TReq extends Message<TReq>, TRes extends Message<TRes>> = (
                                                        request: TReq | Properties<TReq>,
                                                        callback?: rpc.ServiceMethodCallback<TRes>
                                                        ) => Promise<Message<TRes>>;
                                                        • A service method part of a rpc.Service as created by Service.create.

                                                          Parameter request

                                                          Request message or plain object

                                                          Parameter callback

                                                          Node-style callback called with the error, if any, and the response message

                                                          Returns

                                                          Promise if callback has been omitted, otherwise undefined

                                                        type ServiceMethodCallback

                                                        type ServiceMethodCallback<TRes extends Message<TRes>> = (
                                                        error: Error | null,
                                                        response?: TRes
                                                        ) => void;
                                                        • A service method callback as used by ServiceMethod.

                                                          Differs from RPCImplCallback in that it is an actual callback of a service method which may not return response = null.

                                                          Parameter error

                                                          Error, if any

                                                          Parameter response

                                                          Response message

                                                        namespace tokenize

                                                        namespace tokenize {}

                                                          function unescape

                                                          unescape: (str: string) => string;
                                                          • Unescapes a string.

                                                            Parameter str

                                                            String to unescape

                                                            Returns

                                                            Unescaped string

                                                          namespace types

                                                          namespace types {}
                                                          • Common type constants.

                                                          variable basic

                                                          const basic: {
                                                          double: number;
                                                          float: number;
                                                          int32: number;
                                                          uint32: number;
                                                          sint32: number;
                                                          fixed32: number;
                                                          sfixed32: number;
                                                          int64: number;
                                                          uint64: number;
                                                          sint64: number;
                                                          fixed64: number;
                                                          sfixed64: number;
                                                          bool: number;
                                                          string: number;
                                                          bytes: number;
                                                          };
                                                          • Basic type wire types.

                                                          variable defaults

                                                          const defaults: {
                                                          double: number;
                                                          float: number;
                                                          int32: number;
                                                          uint32: number;
                                                          sint32: number;
                                                          fixed32: number;
                                                          sfixed32: number;
                                                          int64: number;
                                                          uint64: number;
                                                          sint64: number;
                                                          fixed64: number;
                                                          sfixed64: number;
                                                          bool: boolean;
                                                          string: string;
                                                          bytes: number[];
                                                          message: null;
                                                          };
                                                          • Basic type defaults.

                                                          variable long

                                                          const long: {
                                                          int64: number;
                                                          uint64: number;
                                                          sint64: number;
                                                          fixed64: number;
                                                          sfixed64: number;
                                                          };
                                                          • Basic long type wire types.

                                                          variable mapKey

                                                          const mapKey: {
                                                          int32: number;
                                                          uint32: number;
                                                          sint32: number;
                                                          fixed32: number;
                                                          sfixed32: number;
                                                          int64: number;
                                                          uint64: number;
                                                          sint64: number;
                                                          fixed64: number;
                                                          sfixed64: number;
                                                          bool: number;
                                                          string: number;
                                                          };
                                                          • Allowed types for map keys with their associated wire type.

                                                          variable packed

                                                          const packed: {
                                                          double: number;
                                                          float: number;
                                                          int32: number;
                                                          uint32: number;
                                                          sint32: number;
                                                          fixed32: number;
                                                          sfixed32: number;
                                                          int64: number;
                                                          uint64: number;
                                                          sint64: number;
                                                          fixed64: number;
                                                          sfixed64: number;
                                                          bool: number;
                                                          };
                                                          • Allowed types for packed repeated fields with their associated wire type.

                                                          namespace util

                                                          namespace util {}
                                                          • Various utility functions.

                                                          variable Array

                                                          let Array: Constructor<Uint8Array>;
                                                          • Array implementation used in the browser. Uint8Array if supported, otherwise Array.

                                                          variable Buffer

                                                          let Buffer: Constructor<Buffer>;
                                                          • Node's Buffer class if available.

                                                          variable decorateRoot

                                                          let decorateRoot: Root;
                                                          • Decorator root (TypeScript).

                                                          variable emptyArray

                                                          const emptyArray: any[];
                                                          • An immuable empty array.

                                                          variable emptyObject

                                                          const emptyObject: {};
                                                          • An immutable empty object.

                                                          variable fs

                                                          let fs: { [k: string]: any };
                                                          • Node's fs module if available.

                                                          variable global

                                                          let global: {};
                                                          • Global object reference.

                                                          variable isNode

                                                          let isNode: boolean;
                                                          • Whether running within node or not.

                                                          variable key2Re

                                                          const key2Re: RegExp;
                                                          • Regular expression used to verify 2 bit (bool) map keys.

                                                          variable key32Re

                                                          const key32Re: RegExp;
                                                          • Regular expression used to verify 32 bit (int32 etc.) map keys.

                                                          variable key64Re

                                                          const key64Re: RegExp;
                                                          • Regular expression used to verify 64 bit (int64 etc.) map keys.

                                                          variable Long

                                                          let Long: Constructor<Long>;
                                                          • Long.js's Long class if available.

                                                          variable toJSONOptions

                                                          let toJSONOptions: IConversionOptions;
                                                          • Default conversion options used for Message#toJSON implementations.

                                                            These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:

                                                            - Longs become strings - Enums become string keys - Bytes become base64 encoded strings - (Sub-)Messages become plain objects - Maps become plain objects with all string keys - Repeated fields become arrays - NaN and Infinity for float and double fields become strings

                                                            See Also

                                                            • https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json

                                                          function asPromise

                                                          asPromise: (fn: asPromiseCallback, ctx: any, ...params: any[]) => Promise<any>;
                                                          • Returns a promise from a node-style callback function.

                                                            Parameter fn

                                                            Function to call

                                                            Parameter ctx

                                                            Function context

                                                            Parameter params

                                                            Function arguments

                                                            Returns

                                                            Promisified function

                                                          function camelCase

                                                          camelCase: (str: string) => string;
                                                          • Converts a string to camel case.

                                                            Parameter str

                                                            String to convert

                                                            Returns

                                                            Converted string

                                                          function codegen

                                                          codegen: typeof codegen;
                                                          • Begins generating a function.

                                                            Parameter functionParams

                                                            Function parameter names

                                                            Parameter functionName

                                                            Function name if not anonymous

                                                            Returns

                                                            Appender that appends code to the function's body

                                                          • Begins generating a function.

                                                            Parameter functionName

                                                            Function name if not anonymous

                                                            Returns

                                                            Appender that appends code to the function's body

                                                          function compareFieldsById

                                                          compareFieldsById: (a: Field, b: Field) => number;
                                                          • Compares reflected fields by id.

                                                            Parameter a

                                                            First field

                                                            Parameter b

                                                            Second field

                                                            Returns

                                                            Comparison value

                                                          function decorateEnum

                                                          decorateEnum: (object: object) => Enum;
                                                          • Decorator helper for enums (TypeScript).

                                                            Parameter object

                                                            Enum object

                                                            Returns

                                                            Reflected enum

                                                          function decorateType

                                                          decorateType: <T extends Message<T>>(
                                                          ctor: Constructor<T>,
                                                          typeName?: string
                                                          ) => Type;
                                                          • Decorator helper for types (TypeScript).

                                                            Parameter ctor

                                                            Constructor function

                                                            Parameter typeName

                                                            Type name, defaults to the constructor's name

                                                            Returns

                                                            Reflected type

                                                          function fetch

                                                          fetch: {
                                                          (filename: string, options: IFetchOptions, callback: FetchCallback): void;
                                                          (path: string, callback: FetchCallback): void;
                                                          (path: string, options?: IFetchOptions): Promise<string | Uint8Array>;
                                                          };
                                                          • Fetches the contents of a file.

                                                            Parameter filename

                                                            File path or url

                                                            Parameter options

                                                            Fetch options

                                                            Parameter callback

                                                            Callback function

                                                          • Fetches the contents of a file.

                                                            Parameter path

                                                            File path or url

                                                            Parameter callback

                                                            Callback function

                                                          • Fetches the contents of a file.

                                                            Parameter path

                                                            File path or url

                                                            Parameter options

                                                            Fetch options

                                                            Returns

                                                            Promise

                                                          function inquire

                                                          inquire: (moduleName: string) => object;
                                                          • Requires a module only if available.

                                                            Parameter moduleName

                                                            Module to require

                                                            Returns

                                                            Required module if available and not empty, otherwise null

                                                          function isInteger

                                                          isInteger: (value: any) => boolean;
                                                          • Tests if the specified value is an integer.

                                                            Parameter value

                                                            Value to test

                                                            Returns

                                                            true if the value is an integer

                                                          function isObject

                                                          isObject: (value: any) => boolean;
                                                          • Tests if the specified value is a non-null object.

                                                            Parameter value

                                                            Value to test

                                                            Returns

                                                            true if the value is a non-null object

                                                          function isReserved

                                                          isReserved: (name: string) => boolean;
                                                          • Tests whether the specified name is a reserved word in JS.

                                                            Parameter name

                                                            Name to test

                                                            Returns

                                                            true if reserved, otherwise false

                                                          function isset

                                                          isset: (obj: object, prop: string) => boolean;
                                                          • Checks if a property on a message is considered to be present. This is an alias of util.isSet.

                                                            Parameter obj

                                                            Plain object or message instance

                                                            Parameter prop

                                                            Property name

                                                            Returns

                                                            true if considered to be present, otherwise false

                                                          function isSet

                                                          isSet: (obj: object, prop: string) => boolean;
                                                          • Checks if a property on a message is considered to be present.

                                                            Parameter obj

                                                            Plain object or message instance

                                                            Parameter prop

                                                            Property name

                                                            Returns

                                                            true if considered to be present, otherwise false

                                                          function isString

                                                          isString: (value: any) => boolean;
                                                          • Tests if the specified value is a string.

                                                            Parameter value

                                                            Value to test

                                                            Returns

                                                            true if the value is a string

                                                          function lcFirst

                                                          lcFirst: (str: string) => string;
                                                          • Converts the first character of a string to lower case.

                                                            Parameter str

                                                            String to convert

                                                            Returns

                                                            Converted string

                                                          function longFromHash

                                                          longFromHash: (hash: string, unsigned?: boolean) => Long | number;
                                                          • Converts an 8 characters long hash string to a long or number.

                                                            Parameter hash

                                                            Hash

                                                            Parameter unsigned

                                                            Whether unsigned or not

                                                            Returns

                                                            Original value

                                                          function longToHash

                                                          longToHash: (value: Long | number) => string;
                                                          • Converts a number or long to an 8 characters long hash string.

                                                            Parameter value

                                                            Value to convert

                                                            Returns

                                                            Hash

                                                          function merge

                                                          merge: (
                                                          dst: { [k: string]: any },
                                                          src: { [k: string]: any },
                                                          ifNotSet?: boolean
                                                          ) => { [k: string]: any };
                                                          • Merges the properties of the source object into the destination object.

                                                            Parameter dst

                                                            Destination object

                                                            Parameter src

                                                            Source object

                                                            Parameter ifNotSet

                                                            Merges only if the key is not already set

                                                            Returns

                                                            Destination object

                                                          function newBuffer

                                                          newBuffer: (sizeOrArray?: number | number[]) => Uint8Array | Buffer;
                                                          • Creates a new buffer of whatever type supported by the environment.

                                                            Parameter sizeOrArray

                                                            Buffer size or number array

                                                            Returns

                                                            Buffer

                                                          function newError

                                                          newError: (name: string) => Constructor<Error>;
                                                          • Creates a custom error constructor.

                                                            Parameter name

                                                            Error name

                                                            Returns

                                                            Custom error constructor

                                                          function oneOfGetter

                                                          oneOfGetter: (fieldNames: string[]) => OneOfGetter;
                                                          • Builds a getter for a oneof's present field name.

                                                            Parameter fieldNames

                                                            Field names

                                                            Returns

                                                            Unbound getter

                                                          function oneOfSetter

                                                          oneOfSetter: (fieldNames: string[]) => OneOfSetter;
                                                          • Builds a setter for a oneof's present field name.

                                                            Parameter fieldNames

                                                            Field names

                                                            Returns

                                                            Unbound setter

                                                          function pool

                                                          pool: (alloc: PoolAllocator, slice: PoolSlicer, size?: number) => PoolAllocator;
                                                          • A general purpose buffer pool.

                                                            Parameter alloc

                                                            Allocator

                                                            Parameter slice

                                                            Slicer

                                                            Parameter size

                                                            Slab size

                                                            Returns

                                                            Pooled allocator

                                                          function safeProp

                                                          safeProp: (prop: string) => string;
                                                          • Returns a safe property accessor for the specified property name.

                                                            Parameter prop

                                                            Property name

                                                            Returns

                                                            Safe accessor

                                                          function setProperty

                                                          setProperty: (
                                                          dst: { [k: string]: any },
                                                          path: string,
                                                          value: object
                                                          ) => { [k: string]: any };
                                                          • Sets the value of a property by property path. If a value already exists, it is turned to an array

                                                            Parameter dst

                                                            Destination object

                                                            Parameter path

                                                            dot '.' delimited path of the property to set

                                                            Parameter value

                                                            the value to set

                                                            Returns

                                                            Destination object

                                                          function toArray

                                                          toArray: (object: { [k: string]: any }) => any[];
                                                          • Converts an object's values to an array.

                                                            Parameter object

                                                            Object to convert

                                                            Returns

                                                            Converted array

                                                          function toObject

                                                          toObject: (array: any[]) => { [k: string]: any };
                                                          • Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.

                                                            Parameter array

                                                            Array to convert

                                                            Returns

                                                            Converted object

                                                          function ucFirst

                                                          ucFirst: (str: string) => string;
                                                          • Converts the first character of a string to upper case.

                                                            Parameter str

                                                            String to convert

                                                            Returns

                                                            Converted string

                                                          class EventEmitter

                                                          class EventEmitter {}
                                                          • A minimal event emitter.

                                                          constructor

                                                          constructor();
                                                          • Constructs a new event emitter instance.

                                                          method emit

                                                          emit: (evt: string, ...args: any[]) => this;
                                                          • Emits an event by calling its listeners with the specified arguments.

                                                            Parameter evt

                                                            Event name

                                                            Parameter args

                                                            Arguments

                                                            Returns

                                                            this

                                                          method off

                                                          off: (evt?: string, fn?: EventEmitterListener) => this;
                                                          • Removes an event listener or any matching listeners if arguments are omitted.

                                                            Parameter evt

                                                            Event name. Removes all listeners if omitted.

                                                            Parameter fn

                                                            Listener to remove. Removes all listeners of evt if omitted.

                                                            Returns

                                                            this

                                                          method on

                                                          on: (evt: string, fn: EventEmitterListener, ctx?: any) => this;
                                                          • Registers an event listener.

                                                            Parameter evt

                                                            Event name

                                                            Parameter fn

                                                            Listener

                                                            Parameter ctx

                                                            Listener context

                                                            Returns

                                                            this

                                                          class LongBits

                                                          class LongBits {}
                                                          • Helper class for working with the low and high bits of a 64 bit value.

                                                          constructor

                                                          constructor(lo: number, hi: number);
                                                          • Constructs new long bits.

                                                            Parameter lo

                                                            Low 32 bits, unsigned

                                                            Parameter hi

                                                            High 32 bits, unsigned

                                                          property hi

                                                          hi: number;
                                                          • High bits.

                                                          property lo

                                                          lo: number;
                                                          • Low bits.

                                                          property zero

                                                          static zero: LongBits;
                                                          • Zero bits.

                                                          property zeroHash

                                                          static zeroHash: string;
                                                          • Zero hash.

                                                          method from

                                                          static from: (value: Long | number | string) => util.LongBits;
                                                          • Constructs new long bits from a number, long or string.

                                                            Parameter value

                                                            Value

                                                            Returns

                                                            Instance

                                                          method fromHash

                                                          static fromHash: (hash: string) => util.LongBits;
                                                          • Constructs new long bits from the specified 8 characters long hash.

                                                            Parameter hash

                                                            Hash

                                                            Returns

                                                            Bits

                                                          method fromNumber

                                                          static fromNumber: (value: number) => util.LongBits;
                                                          • Constructs new long bits from the specified number.

                                                            Parameter value

                                                            Value

                                                            Returns

                                                            Instance

                                                          method length

                                                          length: () => number;
                                                          • Calculates the length of this longbits when encoded as a varint.

                                                            Returns

                                                            Length

                                                          method toHash

                                                          toHash: () => string;
                                                          • Converts this long bits to a 8 characters long hash.

                                                            Returns

                                                            Hash

                                                          method toLong

                                                          toLong: (unsigned?: boolean) => Long;
                                                          • Converts this long bits to a long.

                                                            Parameter unsigned

                                                            Whether unsigned or not

                                                            Returns

                                                            Long

                                                          method toNumber

                                                          toNumber: (unsigned?: boolean) => number;
                                                          • Converts this long bits to a possibly unsafe JavaScript number.

                                                            Parameter unsigned

                                                            Whether unsigned or not

                                                            Returns

                                                            Possibly unsafe number

                                                          method zzDecode

                                                          zzDecode: () => util.LongBits;
                                                          • Zig-zag decodes this long bits.

                                                            Returns

                                                            this

                                                          method zzEncode

                                                          zzEncode: () => util.LongBits;
                                                          • Zig-zag encodes this long bits.

                                                            Returns

                                                            this

                                                          class ProtocolError

                                                          class ProtocolError<T extends Message<T>> extends Error {}
                                                          • Error subclass indicating a protocol specifc error.

                                                          constructor

                                                          constructor(message: string, properties?: { [k: string]: any });
                                                          • Constructs a new protocol error.

                                                            Parameter message

                                                            Error message

                                                            Parameter properties

                                                            Additional properties

                                                          property instance

                                                          instance: Message<T>;
                                                          • So far decoded message instance.

                                                          namespace util.base64

                                                          namespace util.base64 {}
                                                          • A minimal base64 implementation for number arrays.

                                                          function decode

                                                          decode: (string: string, buffer: Uint8Array, offset: number) => number;
                                                          • Decodes a base64 encoded string to a buffer.

                                                            Parameter string

                                                            Source string

                                                            Parameter buffer

                                                            Destination buffer

                                                            Parameter offset

                                                            Destination offset

                                                            Returns

                                                            Number of bytes written

                                                            Throws

                                                            {Error} If encoding is invalid

                                                          function encode

                                                          encode: (buffer: Uint8Array, start: number, end: number) => string;
                                                          • Encodes a buffer to a base64 encoded string.

                                                            Parameter buffer

                                                            Source buffer

                                                            Parameter start

                                                            Source start

                                                            Parameter end

                                                            Source end

                                                            Returns

                                                            Base64 encoded string

                                                          function length

                                                          length: (string: string) => number;
                                                          • Calculates the byte length of a base64 encoded string.

                                                            Parameter string

                                                            Base64 encoded string

                                                            Returns

                                                            Byte length

                                                          function test

                                                          test: (string: string) => boolean;
                                                          • Tests if the specified string appears to be base64 encoded.

                                                            Parameter string

                                                            String to test

                                                            Returns

                                                            true if probably base64 encoded, otherwise false

                                                          namespace util.codegen

                                                          namespace util.codegen {}

                                                            variable verbose

                                                            let verbose: boolean;
                                                            • When set to true, codegen will log generated code to console. Useful for debugging.

                                                            namespace util.float

                                                            namespace util.float {}
                                                            • Reads / writes floats / doubles from / to buffers.

                                                            function readDoubleBE

                                                            readDoubleBE: (buf: Uint8Array, pos: number) => number;
                                                            • Reads a 64 bit double from a buffer using big endian byte order.

                                                              Parameter buf

                                                              Source buffer

                                                              Parameter pos

                                                              Source buffer offset

                                                              Returns

                                                              Value read

                                                            function readDoubleLE

                                                            readDoubleLE: (buf: Uint8Array, pos: number) => number;
                                                            • Reads a 64 bit double from a buffer using little endian byte order.

                                                              Parameter buf

                                                              Source buffer

                                                              Parameter pos

                                                              Source buffer offset

                                                              Returns

                                                              Value read

                                                            function readFloatBE

                                                            readFloatBE: (buf: Uint8Array, pos: number) => number;
                                                            • Reads a 32 bit float from a buffer using big endian byte order.

                                                              Parameter buf

                                                              Source buffer

                                                              Parameter pos

                                                              Source buffer offset

                                                              Returns

                                                              Value read

                                                            function readFloatLE

                                                            readFloatLE: (buf: Uint8Array, pos: number) => number;
                                                            • Reads a 32 bit float from a buffer using little endian byte order.

                                                              Parameter buf

                                                              Source buffer

                                                              Parameter pos

                                                              Source buffer offset

                                                              Returns

                                                              Value read

                                                            function writeDoubleBE

                                                            writeDoubleBE: (val: number, buf: Uint8Array, pos: number) => void;
                                                            • Writes a 64 bit double to a buffer using big endian byte order.

                                                              Parameter val

                                                              Value to write

                                                              Parameter buf

                                                              Target buffer

                                                              Parameter pos

                                                              Target buffer offset

                                                            function writeDoubleLE

                                                            writeDoubleLE: (val: number, buf: Uint8Array, pos: number) => void;
                                                            • Writes a 64 bit double to a buffer using little endian byte order.

                                                              Parameter val

                                                              Value to write

                                                              Parameter buf

                                                              Target buffer

                                                              Parameter pos

                                                              Target buffer offset

                                                            function writeFloatBE

                                                            writeFloatBE: (val: number, buf: Uint8Array, pos: number) => void;
                                                            • Writes a 32 bit float to a buffer using big endian byte order.

                                                              Parameter val

                                                              Value to write

                                                              Parameter buf

                                                              Target buffer

                                                              Parameter pos

                                                              Target buffer offset

                                                            function writeFloatLE

                                                            writeFloatLE: (val: number, buf: Uint8Array, pos: number) => void;
                                                            • Writes a 32 bit float to a buffer using little endian byte order.

                                                              Parameter val

                                                              Value to write

                                                              Parameter buf

                                                              Target buffer

                                                              Parameter pos

                                                              Target buffer offset

                                                            namespace util.path

                                                            namespace util.path {}
                                                            • A minimal path module to resolve Unix, Windows and URL paths alike.

                                                            function isAbsolute

                                                            isAbsolute: (path: string) => boolean;
                                                            • Tests if the specified path is absolute.

                                                              Parameter path

                                                              Path to test

                                                              Returns

                                                              true if path is absolute

                                                            function normalize

                                                            normalize: (path: string) => string;
                                                            • Normalizes the specified path.

                                                              Parameter path

                                                              Path to normalize

                                                              Returns

                                                              Normalized path

                                                            function resolve

                                                            resolve: (
                                                            originPath: string,
                                                            includePath: string,
                                                            alreadyNormalized?: boolean
                                                            ) => string;
                                                            • Resolves the specified include path against the specified origin path.

                                                              Parameter originPath

                                                              Path to the origin file

                                                              Parameter includePath

                                                              Include path relative to origin path

                                                              Parameter alreadyNormalized

                                                              true if both paths are already known to be normalized

                                                              Returns

                                                              Path to the include file

                                                            namespace util.utf8

                                                            namespace util.utf8 {}
                                                            • A minimal UTF8 implementation for number arrays.

                                                            function length

                                                            length: (string: string) => number;
                                                            • Calculates the UTF8 byte length of a string.

                                                              Parameter string

                                                              String

                                                              Returns

                                                              Byte length

                                                            function read

                                                            read: (buffer: Uint8Array, start: number, end: number) => string;
                                                            • Reads UTF8 bytes as a string.

                                                              Parameter buffer

                                                              Source buffer

                                                              Parameter start

                                                              Source start

                                                              Parameter end

                                                              Source end

                                                              Returns

                                                              String read

                                                            function write

                                                            write: (string: string, buffer: Uint8Array, offset: number) => number;
                                                            • Writes a string as UTF8 bytes.

                                                              Parameter string

                                                              Source string

                                                              Parameter buffer

                                                              Destination buffer

                                                              Parameter offset

                                                              Destination offset

                                                              Returns

                                                              Bytes written

                                                            Package Files (1)

                                                            Dependencies (12)

                                                            Dev Dependencies (30)

                                                            Peer Dependencies (0)

                                                            No peer dependencies.

                                                            Badge

                                                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/protobufjs.

                                                            • Markdown
                                                              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/protobufjs)
                                                            • HTML
                                                              <a href="https://www.jsdocs.io/package/protobufjs"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>