new Type(name, options)
Constructs a new reflected message type instance.
Name | Type | Description |
---|---|---|
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.
-
reserved { (number[]|string)[] }
-
Reserved ranges, if any.
-
resolved { boolean }
-
Whether already resolved or not.
-
root readonly{ Root }
-
Reference to the root namespace.
Methods
-
Type.d(typeName){ TypeDecorator.<T> }
-
Type decorator (TypeScript).
Name Type Description typeName
string optional Type name, defaults to the constructor's name
Returns:
Type Description TypeDecorator.<T> Decorator function -
Type.fromJSON(name, json){ Type }
-
Creates a message type from a message type descriptor.
Name Type Description name
string Message name
json
IType Message type descriptor
Returns:
Type Description Type Created message type -
Type.generateConstructor(mtype){ Codegen }
-
Generates a constructor function for the specified type.
Name Type Description mtype
Type Message type
Returns:
Type Description Codegen Codegen instance -
add(object){ Type }
-
Adds a nested object to this type.
Name Type Description object
ReflectionObject Nested object to add
Throws:
-
Type Description TypeError If arguments are invalid
-
Type Description 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 Description Type this
-
-
Adds nested objects to this namespace from nested object descriptors.
Name Type Description nestedJson
Object.<string, AnyNestedObject> Any nested object descriptors
Returns:
Type Description Namespace this
-
create(properties){ Message.<{}> }
-
Creates a new message of this type using the specified properties.
Name Type Description properties
Object.<string, *> optional Properties to set
Returns:
Type Description Message.<{}> Message instance -
decode(reader, length){ Message.<{}> }
-
Decodes a message of this type.
Name Type Description reader
Reader | Uint8Array Reader or buffer to decode from
length
number optional Length of the message, if known beforehand
Throws:
-
Type Description Error If the payload is not a reader or valid buffer
-
Type Description util.ProtocolError.<{}> If required fields are missing
Returns:
Type Description Message.<{}> Decoded message -
-
decodeDelimited(reader){ Message.<{}> }
-
Decodes a message of this type preceeded by its byte length as a varint.
Name Type Description reader
Reader | Uint8Array Reader or buffer to decode from
Throws:
-
Type Description Error If the payload is not a reader or valid buffer
-
Type Description util.ProtocolError If required fields are missing
Returns:
Type Description Message.<{}> Decoded message -
-
Defines additial namespaces within this one if not yet existing.
Name Type Description path
string | Array.<string> Path to create
json
* optional Nested types to create from JSON
Returns:
Type Description 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.
Name Type Description message
Message.<{}> | Object.<string, *> Message instance or plain object
writer
Writer optional Writer to encode to
Returns:
Type Description 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.
Name Type Description message
Message.<{}> | Object.<string, *> Message instance or plain object
writer
Writer optional Writer to encode to
Returns:
Type Description Writer writer -
fromObject(object){ Message.<{}> }
-
Creates a new message of this type from a plain object. Also converts values to their respective internal types.
Name Type Description object
Object.<string, *> Plain object to convert
Returns:
Type Description Message.<{}> Message instance -
inherited get(name){ ReflectionObject | null }
-
Gets the nested object of the specified name.
Name Type Description name
string Nested object name
Returns:
Type Description 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 returningnull
.Name Type Description name
string Nested enum name
Throws:
Type Description Error If there is no such enum
Returns:
Type Description Object.<string, number> Enum values -
inherited getOption(name){ * }
-
Gets an option value.
Name Type Description name
string Option name
Returns:
Type Description * Option value or undefined
if not set -
isReservedId(id){ boolean }
-
Tests if the specified id is reserved.
Name Type Description id
number Id to test
Returns:
Type Description boolean true
if reserved, otherwisefalse
-
isReservedName(name){ boolean }
-
Tests if the specified name is reserved.
Name Type Description name
string Name to test
Returns:
Type Description boolean true
if reserved, otherwisefalse
-
inherited lookup(path, filterTypes, parentAlreadyChecked){ ReflectionObject | null }
-
Recursively looks up the reflection object matching the specified path in the scope of this namespace.
Name Type Default Description 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:
Type Description 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.
Name Type Default Description path
string | Array.<string> Path to look up
parentAlreadyChecked
boolean false optional Whether the parent has already been checked
Returns:
Type Description ReflectionObject | null Looked up object or null
if none could be found -
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 returningnull
.Name Type Description path
string | Array.<string> Path to look up
Throws:
Type Description Error If
path
does not point to an enumReturns:
Type Description Enum Looked up enum -
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 returningnull
.Name Type Description path
string | Array.<string> Path to look up
Throws:
Type Description Error If
path
does not point to a serviceReturns:
Type Description Service Looked up service -
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 returningnull
.Name Type Description path
string | Array.<string> Path to look up
Throws:
Type Description Error If
path
does not point to a typeReturns:
Type Description Type Looked up 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 returningnull
.Name Type Description path
string | Array.<string> Path to look up
Throws:
Type Description Error If
path
does not point to a type or enumReturns:
Type Description Type Looked up type or enum -
inherited onAdd(parent){ undefined }
-
Called when this object is added to a parent.
Name Type Description parent
ReflectionObject Parent added to
Returns:
Type Description undefined -
inherited onRemove(parent){ undefined }
-
Called when this object is removed from a parent.
Name Type Description parent
ReflectionObject Parent removed from
Returns:
Type Description undefined -
remove(object){ Type }
-
Removes a nested object from this type.
Name Type Description object
ReflectionObject Nested object to remove
Throws:
-
Type Description TypeError If arguments are invalid
-
Type Description Error If
object
is not a member of this type
Returns:
Type Description Type this
-
-
inherited resolve(){ ReflectionObject }
-
Resolves this objects type references.
Returns:
Type Description ReflectionObject this
-
Resolves this namespace's and all its nested objects' type references. Useful to validate a reflection tree, but comes at a cost.
Returns:
Type Description Namespace this
-
inherited setOption(name, value, ifNotSet){ ReflectionObject }
-
Sets an option.
Name Type Description name
string Option name
value
* Option value
ifNotSet
boolean optional Sets the option only if it isn't currently set
Returns:
Type Description ReflectionObject this
-
inherited setOptions(options, ifNotSet){ ReflectionObject }
-
Sets multiple options.
Name Type Description options
Object.<string, *> Options to set
ifNotSet
boolean optional Sets an option only if it isn't currently set
Returns:
Type Description ReflectionObject this
-
setup(){ Type }
-
Returns:
Type Description Type this
-
toJSON(){ IType }
-
Converts this message type to a message type descriptor.
Returns:
Type Description 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.
Name Type Description message
Message.<{}> Message instance
options
IConversionOptions optional Conversion options
Returns:
Type Description Object.<string, *> Plain object -
inherited toString(){ string }
-
Converts this instance to its string representation.
Returns:
Type Description string Class name[, space, full name] -
verify(message){ null | string }
-
Verifies that field values are valid and that required fields are present.
Name Type Description message
Object.<string, *> Plain object to verify
Returns:
Type Description null | string null
if valid, otherwise the reason why it is not