Class: Type

Type

Reflected message type.

new Type(name, options)

Constructs a new reflected message type instance.

Parameters:
name string

Message name

options Object.<string, *> optional

Declared options

Extends

Members

comment { string | null }

Comment text, if any.

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.

extensions { number[][] }

Extension ranges, if any.

fields { Object<string, Field> }

Message fields.

fieldsArray readonly{ Field[] }

Fields of this message as an array for iteration.

fieldsById readonly{ Object<number, Field> }

Message fields by id.

filename { string | null }

Defining file name.

fullName readonly{ string }

Full name including leading dot.

name { string }

Unique name within its namespace.

nested { Object<string, ReflectionObject> | undefined }

Nested objects by name.

nestedArray readonly{ ReflectionObject[] }

Nested objects of this namespace as an array for iteration.

oneofs { Object<string, OneOf> }

Oneofs declared within this namespace, if any.

oneofsArray readonly{ OneOf[] }

Oneofs of this message as an array for iteration.

options { Object<string, *> | undefined }

Options.

parent { Namespace | null }

Parent namespace.

parsedOptions { Object<string, *>[] | undefined }

Parsed Options.

reserved { (number[]|string)[] }

Reserved ranges, if any.

resolved { boolean }

Whether already resolved or not.

root readonly{ Root }

Reference to the root namespace.

Methods

add(object){ Type }

Adds a nested object to this type.

Parameters:
object ReflectionObject

Nested object to add

Throws:
TypeError

If arguments are invalid

Error

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

Returns:
Type this

inherited addJSON(nestedJson, depth){ Namespace }

Adds nested objects to this namespace from nested object descriptors.

Parameters:
nestedJson Object.<string, AnyNestedObject>

Any nested object descriptors

depth number optional

Current nesting depth, defaults to 0

Returns:
Namespace this

create(properties){ Message.<{}> }

Creates a new message of this type using the specified properties.

Parameters:
properties Object.<string, *> optional

Properties to set

Returns:
Message.<{}> Message instance

decode(reader, length){ Message.<{}> }

Decodes a message of this type.

Parameters:
reader Reader | Uint8Array

Reader or buffer to decode from

length number optional

Length of the message, if known beforehand

Throws:
Error

If the payload is not a reader or valid buffer

util.ProtocolError.<{}>

If required fields are missing

Returns:
Message.<{}> Decoded message

decodeDelimited(reader){ Message.<{}> }

Decodes a message of this type preceeded by its byte length as a varint.

Parameters:
reader Reader | Uint8Array

Reader or buffer to decode from

Throws:
Error

If the payload is not a reader or valid buffer

util.ProtocolError

If required fields are missing

Returns:
Message.<{}> Decoded message

inherited define(path, json){ Namespace }

Defines additial namespaces within this one if not yet existing.

Parameters:
path string | Array.<string>

Path to create

json * optional

Nested types to create from JSON

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

encode(message, writer){ Writer }

Encodes a message of this type. Does not implicitly verify messages.

Parameters:
message Message.<{}> | Object.<string, *>

Message instance or plain object

writer Writer optional

Writer to encode to

Returns:
Writer writer

encodeDelimited(message, writer){ Writer }

Encodes a message of this type preceeded by its byte length as a varint. Does not implicitly verify messages.

Parameters:
message Message.<{}> | Object.<string, *>

Message instance or plain object

writer Writer optional

Writer to encode to

Returns:
Writer writer

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

Creates a new message of this type from a plain object. Also converts values to their respective internal types.

Parameters:
object Object.<string, *>

Plain object to convert

Returns:
Message.<{}> Message instance

inherited get(name){ ReflectionObject | null }

Gets the nested object of the specified name.

Parameters:
name string

Nested object name

Returns:
ReflectionObject | null The reflection object or null if it doesn't exist

inherited getEnum(name){ Object<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.

Parameters:
name string

Nested enum name

Throws:
Error

If there is no such enum

Returns:
Object.<string, number> Enum values

inherited getOption(name){ * }

Gets an option value.

Parameters:
name string

Option name

Returns:
* Option value or undefined if not set

getTypeUrl(prefix){ string }

Gets the type url for this type.

Parameters:
prefix string optional

Custom type url prefix, defaults to "type.googleapis.com"

Returns:
string The type url

isReservedId(id){ boolean }

Tests if the specified id is reserved.

Parameters:
id number

Id to test

Returns:
boolean true if reserved, otherwise false

isReservedName(name){ boolean }

Tests if the specified name is reserved.

Parameters:
name string

Name to test

Returns:
boolean true if reserved, otherwise false

inherited lookup(path, filterTypes, parentAlreadyChecked){ ReflectionObject | null }

Recursively looks up the reflection object matching the specified path in the scope of this namespace.

Parameters:
path string | Array.<string>

Path to look up

filterTypes * | Array.<*>

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

parentAlreadyChecked boolean false optional

If known, whether the parent has already been checked

Returns:
ReflectionObject | null Looked up object or null if none could be found

inherited lookup(path, parentAlreadyChecked){ ReflectionObject | null }

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

Parameters:
path string | Array.<string>

Path to look up

parentAlreadyChecked boolean false optional

Whether the parent has already been checked

Returns:
ReflectionObject | null Looked up object or null if none could be found

inherited lookupEnum(path){ 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.

Parameters:
path string | Array.<string>

Path to look up

Throws:
Error

If path does not point to an enum

Returns:
Enum Looked up enum

inherited lookupService(path){ 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.

Parameters:
path string | Array.<string>

Path to look up

Throws:
Error

If path does not point to a service

Returns:
Service Looked up service

inherited lookupType(path){ 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.

Parameters:
path string | Array.<string>

Path to look up

Throws:
Error

If path does not point to a type

Returns:
Type Looked up type

inherited lookupTypeOrEnum(path){ 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.

Parameters:
path string | Array.<string>

Path to look up

Throws:
Error

If path does not point to a type or enum

Returns:
Type Looked up type or enum

inherited onAdd(parent){ undefined }

Called when this object is added to a parent.

Parameters:
parent ReflectionObject

Parent added to

Returns:
undefined

inherited onRemove(parent){ undefined }

Called when this object is removed from a parent.

Parameters:
parent ReflectionObject

Parent removed from

Returns:
undefined

remove(object){ Type }

Removes a nested object from this type.

Parameters:
object ReflectionObject

Nested object to remove

Throws:
TypeError

If arguments are invalid

Error

If object is not a member of this type

Returns:
Type this

Resolves this objects type references.

Returns:
ReflectionObject this

inherited 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:
Namespace this

inherited setOption(name, value, ifNotSet){ ReflectionObject }

Sets an option.

Parameters:
name string

Option name

value *

Option value

ifNotSet boolean | undefined optional

Sets the option only if it isn't currently set

Returns:
ReflectionObject this

inherited setOptions(options, ifNotSet){ ReflectionObject }

Sets multiple options.

Parameters:
options Object.<string, *>

Options to set

ifNotSet boolean optional

Sets an option only if it isn't currently set

Returns:
ReflectionObject this

inherited setParsedOption(name, value, propName){ ReflectionObject }

Sets a parsed option.

Parameters:
name string

parsed Option name

value *

Option value

propName string

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

Returns:
ReflectionObject this

setup(){ Type }

Sets up encode, decode and verify.

Returns:
Type this

toJSON(toJSONOptions){ IType }

Converts this message type to a message type descriptor.

Parameters:
toJSONOptions IToJSONOptions optional

JSON conversion options

Returns:
IType Message type descriptor

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

Creates a plain object from a message of this type. Also converts values to other types if specified.

Parameters:
message Message.<{}>

Message instance

options IConversionOptions optional

Conversion options

Returns:
Object.<string, *> Plain object

inherited toString(){ string }

Converts this instance to its string representation.

Returns:
string Class name[, space, full name]

verify(message){ null | string }

Verifies that field values are valid and that required fields are present.

Parameters:
message Object.<string, *>

Plain object to verify

Returns:
null | string null if valid, otherwise the reason why it is not

Type.d(typeName){ TypeDecorator.<T> }

Type decorator (TypeScript).

Parameters:
typeName string optional

Type name, defaults to the constructor's name

Deprecated:
Legacy TypeScript decorator support. Will be removed in a future release.
Returns:
TypeDecorator.<T> Decorator function

Type.fromJSON(name, json, depth){ Type }

Creates a message type from a message type descriptor.

Parameters:
name string

Message name

json IType

Message type descriptor

depth number optional

Current nesting depth, defaults to 0

Returns:
Type Created message type

Type.generateConstructor(mtype){ Codegen }

Generates a constructor function for the specified type.

Parameters:
mtype Type

Message type

Returns:
Codegen Codegen instance